I have a gradle-experimental 0.6.0-alpha1 compliant build.gradle file:
apply plugin: 'com.android.model.application'
model {
android {
compileSdkVersion = 21
buildToolsVersion = "23.0.2"
defaultConfig.with {
applicationId = "com.company.application"
minSdkVersion.apiLevel = 21
targetSdkVersion.apiLevel = 21
}
}
android.buildTypes {
release {
minifyEnabled = false
proguardFiles.add(file('proguard-rules.pro'))
}
}
android.ndk {
moduleName = "moduleName"
}
}
dependencies {
compile project(':libcocos2dx')
}
And I am using cocos2dx as my engine. I have a folder hierarchy that looks like this:
Classes (which contains all the C++ code of my project)
proj.android/src/main/projectName/jni (which contains the main.cpp file for cocos2d to hook on)
I also have many other cpp classes that are in a different folders outside the proj.android one (the cocos2d cpp file for example are at proj.android/../../../dependencies/XXXX/cocos2d-x and the engine files are at proj.android/../../../dependencies/XXXX/engine, and all my C++ code is at proj.android/../Classes, as in every cocos2dx project)
I am trying to build my application using the latest gradle experimental plugin (gradle-experimental-0.6.0-alpha1).
I first try to build it as-is, project compile and run but was empty (no libMyApp.so was generated), because I didn't included any C++ source file in my gradle build.
I then made some symbolic link to the source file folder so that gradle could pick them:
ln -s proj.android/../../../dependencies/XXXX/cocos2d-x proj.android/src/main/projectName/jni
Now when I am building (./gradlew assembleDebug), I get it compile symboliquely linked C++ files, but it fails on the first include of header everytime, no matter what I try.
I have tried to add source file/ header include as described here using:
android.sources {
main {
jni {
source {
srcDir "src"
}
exportedHeaders {
srcDir "src"
}
}
}
}
but I couldn't get it to find the missing ".h" headers. If anybody has tried to build a consequent C++ project using cocos2Dx, gradle-experimental and android-studio please feel free to share any experience. I will try to compile some sort of guide when I will be able to compile it (one day :))
for reference: latest gradle doc:
https://docs.gradle.org/2.9/userguide/nativeBinaries.html
usefull link:
http://ph0b.com/new-android-studio-ndk-support/
Hi Thank you for your file, I made some modification to you files.
I works then, I did it with cocos2Dx 3.9 on my Mac OSX.
You need : com.android.tools.build:gradle-experimental:0.6.0-alpha5'
You can put breakpoints in Java and C++ at the same time.
Cyrl
import org.apache.tools.ant.taskdefs.condition.Os
apply plugin: 'com.android.model.library'
model {
repositories {
libs(PrebuiltLibraries) {
chipmunk {
headers.srcDir "../../../../external/chipmunk/include"
binaries.withType(SharedLibraryBinary) {
//
// NOTE: this block should be "StaticLibraryBinary"/staticLibraryFile - but SharedLibraryBinary works and StaticLibraryBinary doesn't as of 0.6.0-alpha2
// bug reported here: https://code.google.com/p/android/issues/detail?id=196065
//
sharedLibraryFile = file("../../../../external/chipmunk/prebuilt/android/${targetPlatform.getName()}/libchipmunk.a")
}
}
freetype2 {
headers.srcDir "../../../../external/freetype2/include/android/freetype2"
binaries.withType(SharedLibraryBinary) {
sharedLibraryFile = file("../../../../external/freetype2/prebuilt/android/${targetPlatform.getName()}/libfreetype.a")
}
}
curl {
headers.srcDir "../../../../external/curl/include/android/curl"
binaries.withType(SharedLibraryBinary) {
sharedLibraryFile = file("../../../../external/curl/prebuilt/android/${targetPlatform.getName()}/libcurl.a")
}
}
png {
headers.srcDir "../../../../external/png/include/android"
binaries.withType(SharedLibraryBinary) {
sharedLibraryFile = file("../../../../external/png/prebuilt/android/${targetPlatform.getName()}/libpng.a")
}
}
jpeg {
headers.srcDir "../../../../external/jpeg/include/android"
binaries.withType(SharedLibraryBinary) {
sharedLibraryFile = file("../../../../external/jpeg/prebuilt/android/${targetPlatform.getName()}/libjpeg.a")
}
}
tiff {
headers.srcDir "../../../../external/tiff/include/android"
binaries.withType(SharedLibraryBinary) {
sharedLibraryFile = file("../../../../external/tiff/prebuilt/android/${targetPlatform.getName()}/libtiff.a")
}
}
webp {
headers.srcDir "../../../../external/webp/include/android"
binaries.withType(SharedLibraryBinary) {
sharedLibraryFile = file("../../../../external/webp/prebuilt/android/${targetPlatform.getName()}/libwebp.a")
}
}
bullet {
headers.srcDir "../../../../external/bullet/"
binaries.withType(SharedLibraryBinary) {
sharedLibraryFile = file("../../../../external/bullet/obj/local/${targetPlatform.getName()}/libbullet.a")
}
}
recast {
headers.srcDir "../../../../external/recast/"
binaries.withType(SharedLibraryBinary) {
sharedLibraryFile = file("../../../../external/recast/obj/local/${targetPlatform.getName()}/librecast.a")
}
}
websockets {
headers.srcDir "../../../../external/websockets/include/android"
binaries.withType(SharedLibraryBinary) {
sharedLibraryFile = file("../../../../external/websockets/prebuilt/android/${targetPlatform.getName()}/libwebsockets.a")
}
}
ssl {
headers.srcDir "../../../../external/curl/include/android/curl"
binaries.withType(SharedLibraryBinary) {
sharedLibraryFile = file("../../../../external/curl/prebuilt/android/${targetPlatform.getName()}/libssl.a")
}
}
crypto {
headers.srcDir "../../../../external/curl/include/android/curl"
binaries.withType(SharedLibraryBinary) {
sharedLibraryFile = file("../../../../external/curl/prebuilt/android/${targetPlatform.getName()}/libcrypto.a")
}
}
}
}
android {
compileSdkVersion = 21
buildToolsVersion = "23.0.2"
defaultConfig.with {
minSdkVersion.apiLevel = 9
targetSdkVersion.apiLevel = 9
}
}
android.ndk {
moduleName = "cocos2dx"
stl = "c++_static"
cppFlags.add("-std=c++11")
cppFlags.add("-pthread")
cppFlags.add("-fexceptions")
cppFlags.add("-frtti")
CFlags.add("-DUSE_FILE32API")
CFlags.add("-fexceptions")
ldLibs.addAll(["atomic", "log", "android", "EGL", "GLESv2", "z" ])
}
android.sources {
main {
manifest.source {
srcDir "."
include "AndroidManifest.xml"
}
jni {
source {
// INTERNAL CPP FILES
//srcDir "../../../../cocos/"
// include only file at this level
srcDir "../../../../cocos/2d"
srcDir "../../../../cocos/sourceFile"
srcDir "../../../../cocos/3d"
srcDir "../../../../cocos/math"
srcDir "../../../../cocos/base"
srcDir "../../../../cocos/platform/sourceFiles"
srcDir "../../../../cocos/cpufeatures"
// include only file at this level
srcDir "../../../../cocos/platform/android"
srcDir "../../../../cocos/renderer"
srcDir "../../../../cocos/deprecated"
srcDir "../../../../cocos/physics"
srcDir "../../../../cocos/physics3d"
srcDir "../../../../cocos/navmesh"
srcDir "../../../../cocos/network"
srcDir "../../../../tests/cpp-empty-test/Classes"
srcDir "../../../../tests/cpp-empty-test/Main"
// EXTERNAL CPP FILES
srcDir "../../../../external/ConvertUTF"
srcDir "../../../../external/tinyxml2"
srcDir "../../../../external/unzip"
srcDir "../../../../external/edtaa3func"
srcDir "../../../../external/poly2tri"
srcDir "../../../../external/clipper"
srcDir "../../../../external/xxhash"
}
exportedHeaders {
// INTERNAL HEADERS
srcDir "../../../../cocos"
srcDir "../../../../cocos/2d"
srcDir "../../../../cocos/math"
srcDir "../../../../cocos/base"
srcDir "../../../../cocos/platform"
srcDir "../../../../cocos/platform/android"
srcDir "../../../../cocos/renderer"
srcDir "../../../../cocos/deprecated"
srcDir "../../../../cocos/physics"
srcDir "../../../../cocos/physics3d"
srcDir "../../../../cocos/navmesh"
srcDir "../../../../tests/cpp-empty-test/Classes"
// EXTERNAL HEADERS
srcDir "../../../../external"
srcDir "../../../../external/ConvertUTF"
srcDir "../../../../external/tinyxml2"
srcDir "../../../../external/unzip"
srcDir "../../../../external/edtaa3func"
srcDir "../../../../external/poly2tri"
srcDir "../../../../external/poly2tri/common"
srcDir "../../../../external/poly2tre/sweep"
srcDir "../../../../external/clipper"
srcDir "../../../../external/xxhash"
// STATIC LIBRARIES
srcDir "../../../../external/chipmunk/include/chipmunk"
srcDir "../../../../external/freetype2/include/android/freetype2"
srcDir "../../../../external/curl/include/android"
srcDir "../../../../external/png/include/android"
srcDir "../../../../external/tiff/include/android"
srcDir "../../../../external/jpeg/include/android"
srcDir "../../../../external/webp/include/android"
srcDir "../../../../external/websockets/include/android"
}
dependencies {
library "chipmunk"
library "freetype2"
library "curl"
library "png"
library "jpeg"
library "tiff"
library "webp"
library "bullet"
library "recast"
library "websockets"
library "ssl"
library "crypto"
}
}
}
}
android.buildTypes {
release {
}
debug {
ndk.with {
debuggable = true
}
}
}
android.productFlavors {
create ("arm") {
ndk.with {
abiFilters.add("armeabi-v7a")
ldFlags.addAll([
"-L${file("./obj/local/armeabi-v7a")}".toString()
])
}
}
create("x86") {
ndk.with {
abiFilters.add("x86")
ldFlags.addAll([
"-L${file("./obj/local/x86")}".toString()
])
}
}
}
}
task buildMkRecast(type: Exec) {
// Retrieve ndk dir
Properties properties = new Properties()
properties.load(project.rootProject.file('local.properties').newDataInputStream())
def ndkDir = properties.getProperty('ndk.dir', null)
// Call ndk build
def ndkBuildExt = Os.isFamily(Os.FAMILY_WINDOWS) ? ".cmd" : ""
commandLine "$ndkDir/ndk-build${ndkBuildExt}",
'-C', file('.').absolutePath,
'NDK_APPLICATION_MK=Application.mk',
'APP_BUILD_SCRIPT=../../../../external/recast/Android.mk',
'NDK_PROJECT_PATH=../../../../external/recast/'
}
task buildMkBullet(dependsOn: "buildMkRecast",type: Exec) {
// Retrieve ndk dir
Properties properties = new Properties()
properties.load(project.rootProject.file('local.properties').newDataInputStream())
def ndkDir = properties.getProperty('ndk.dir', null)
// Call ndk build
def ndkBuildExt = Os.isFamily(Os.FAMILY_WINDOWS) ? ".cmd" : ""
commandLine "$ndkDir/ndk-build${ndkBuildExt}",
'-C', file('.').absolutePath,
'NDK_APPLICATION_MK=Application.mk',
'APP_BUILD_SCRIPT=../../../../external/bullet/Android.mk',
'NDK_PROJECT_PATH=../../../../external/bullet/'
}
tasks.whenTaskAdded { task ->
def taskName = task.name
if (taskName.startsWith("compile")) {
task.dependsOn "buildMkBullet"
}
}
dependencies {
compile files('../java/libs/android-async-http-1.4.8.jar')
}
So I finally made it working by adding the
exportedHeaders {
srcDir "src"
}
line and point it to the right directory where the missing headers were.
Related
I have a Java+Kotlin application, building with Gradle.
Some of its low-level functionality is provided by a separate C++ application.
The two applications communicate via a socket or pipe, using Protocol Buffers and gRPC.
Initially, I'd hoped to build all three (ProtoBuf generated code, Java application, C++ application) in one project, however the cpp-application and java conflict over certain tasks (compile/implementation/test?).
I've since split this into three projects:
/
build.gradle
settings.gradle
cpp-app/
build.gradle
settings.gradle
...
java-app/
build.gradle
settings.gradle
...
protocol/
build.gradle
settings.gradle
build/generated/source/proto/main/java/... <-- Java generated code
build/generated/source/proto/main/cpp/... <-- C++ generated code
...
I have the protocol project successfully generating C++ and Java implementations.
How do I get the C++ and Java application projects to resolve and to use these outputs in their builds?
I solved this while I was writing the question.
The gradle configuration files are shown below. There are a couple redundant blocks which are not needed for this example (or needed at all), however they achieve the objective.
/build.gradle
subprojects {
group = 'com.whatever.your.group'
version = '0.0.0'
repositories {
mavenCentral()
}
}
/settings.gradle
rootProject.name = 'my-project'
include 'java-app'
include 'cpp-app'
include 'protocol'
/java-app/build.gradle
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:1.3.20"
}
}
plugins {
// Java
id 'maven'
id 'idea'
id 'application'
id 'java'
id 'org.jetbrains.kotlin.jvm' version '1.3.20'
// ProtoBuf
id 'com.google.protobuf' version '0.8.8'
}
description = """"""
sourceCompatibility = 8
targetCompatibility = 8
compileKotlin {
kotlinOptions.jvmTarget = "1.8"
}
compileTestKotlin {
kotlinOptions.jvmTarget = "1.8"
}
mainClassName = 'my.main.Class'
dependencies {
protobuf project(':protocol') // <-- name of protobuf project
compile project(':protocol') // <-- name of protobuf project
// We have "protobuf" and "compile", as "compile" brings in transitive dependencies
testCompile 'junit:junit:4.12'
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8:1.3.20"
testImplementation "org.jetbrains.kotlin:kotlin-test:1.3.20"
testImplementation "org.jetbrains.kotlin:kotlin-test-junit:1.3.20"
}
sourceSets {
main {
java {
srcDir "src/main/java"
}
kotlin {
srcDir "src/main/kotlin"
}
}
}
/java-app/settings.gradle
rootProject.name = 'java-app'
/cpp-app/build.gradle
plugins {
id 'maven'
id 'cpp'
}
description = """"""
project.tasks.build.dependsOn 'protocol' // <-- name of protobuf project
model {
components {
main(NativeExecutableSpec) {
...
}
}
...
}
/cpp-app/settings.gradle
rootProject.name = 'cpp-app'
/protocol/build.gradle
plugins {
id 'maven'
id 'java'
id 'com.google.protobuf' version '0.8.8'
}
repositories {
mavenCentral()
}
description = """"""
sourceCompatibility = 8
targetCompatibility = 8
dependencies {
compile 'com.google.protobuf:protobuf-java:3.7.0'
compile 'io.grpc:grpc-stub:1.19.0'
compile 'io.grpc:grpc-protobuf:1.19.0'
}
sourceSets {
main {
proto {
srcDir "src/main/proto"
}
}
}
protobuf {
protoc {
artifact = "com.google.protobuf:protoc:3.7.0"
}
plugins {
grpc_java {
artifact = 'io.grpc:protoc-gen-grpc-java:1.19.0'
}
grpc_cpp {
path = getPluginPath('cpp')
}
grpc_python {
path = getPluginPath('python')
}
}
generateProtoTasks {
generatedFilesBaseDir = "${buildDir}/build/generated/src"
all()*.builtins {
java { }
cpp { }
python { }
}
all()*.plugins {
grpc_java {
outputSubDir = 'java'
}
grpc_cpp {
outputSubDir = 'cpp'
}
grpc_python {
outputSubDir = 'python'
}
}
}
}
clean {
delete protobuf.generatedFilesBaseDir
}
// Used to find executables for generating C++ and Java gRPC
static def getPluginPath(name) {
def path = "which grpc_${name}_plugin".execute()
path.waitFor()
path = path.in.text.trim()
if (!path) {
println "Failed to locate GRPC plugin for ${name}"
} else {
println "Found GRPC plugin for ${name} at ${path}"
}
return path
}
/protocol/settings.gradle
rootProject.name = 'protocol'
Then in the project root, I can run gradle assemble, and:
$ gradle assemble
> Configure project :protocol
Found GRPC plugin for cpp at /usr/bin/grpc_cpp_plugin
Found GRPC plugin for python at /usr/bin/grpc_python_plugin
> Task :cpp-app:linkMainExecutable NO-SOURCE
> Task :cpp-app:mainExecutable UP-TO-DATE
> Task :cpp-app:assemble UP-TO-DATE
> Task :protocol:extractIncludeProto
> Task :protocol:extractProto
> Task :protocol:generateProto
> Task :protocol:compileJava
> Task :protocol:processResources
> Task :protocol:classes
> Task :protocol:jar
> Task :protocol:assemble
> Task :java-app:extractIncludeProto
> Task :java-app:extractProto
> Task :java-app:generateProto
> Task :java-app:compileKotlin
> Task :java-app:compileJava
> Task :java-app:processResources
> Task :java-app:classes
> Task :java-app:inspectClassesForKotlinIC
> Task :java-app:jar
> Task :java-app:startScripts
> Task :java-app:distTar
> Task :java-app:distZip
> Task :java-app:assemble
BUILD SUCCESSFUL in 10s
17 actionable tasks: 17 executed
I'm trying to setup a C++ project that itself uses another (not gradle) C++ project.
Since the compilation doesn't require anything special I tried including the project as a submodule and compiling that library as a library through gradle itself.
To my knowledge I have set up the build script correctly like this:
// Project-Type
apply plugin: "cpp"
// IDEs
apply plugin: "visual-studio"
model {
visualStudio {
solutions.all {
solutionFile.location = "vs/${name}.sln"
solutionFile.withContent { TextProvider content ->
content.asBuilder().insert(0, "# GENERATED FILE: DO NOT EDIT\n")
content.text = content.text.replaceAll("HideSolutionNode = FALSE", "HideSolutionNode = TRUE")
}
}
}
repositories {
libs(PrebuiltLibraries) {
easyloggingpp {
headers.srcDir "lib/easyloggingpp/src"
}
eigen {
headers.srcDir "lib/OpenNN/eigen/src"
}
}
}
platforms {
x86 {
architecture "x86"
}
x64 {
architecture "x64"
}
}
buildTypes {
debug
release
}
components {
tinyxml2(NativeLibrarySpec) {
sources.cpp {
source {
srcDirs "lib/OpenNN"
include "tinyxml2/**/*.cpp"
}
exportedHeaders {
srcDirs "lib/OpenNN"
include "tinyxml2/**/*.h"
}
}
}
openNN(NativeLibrarySpec) {
sources.cpp {
source {
srcDirs "lib/OpenNN"
include "opennn/**/*.cpp"
}
exportedHeaders {
srcDirs "lib/OpenNN"
include "opennn/**/*.h"
}
lib library: "eigen", linkage: "api"
lib library: "tinyxml2", linkage: "static"
}
}
anni(NativeExecutableSpec) {
if(System.properties['sun.arch.data.model'] == "64") {
targetPlatform "x64"
} else {
targetPlatform "x86"
}
sources.cpp {
source {
srcDirs "src"
include "**/*.cpp"
}
exportedHeaders {
srcDirs "src"
include "**/*.hpp"
}
lib library: "easyloggingpp", linkage: "api"
lib library: "openNN", linkage: "static"
}
}
}
binaries {
withType(NativeExecutableBinarySpec) {
if (toolChain in Gcc) {
cppCompiler.args "-Wall", "-Wextra", "-Wpedantic", "-fPIC"
}
if (toolChain in Clang) {
cppCompiler.args "-Weverything", "-pedantic"
}
if (toolChain in VisualCpp) {
cppCompiler.args "/W4", "/FS", "/EHsc"
}
}
withType(SharedLibraryBinary) {
buildable = false
}
withType(StaticLibraryBinarySpec) {
if (toolChain in Gcc) {
cppCompiler.args "-Werror"
}
if (toolChain in Clang) {
cppCompiler.args "-Werror"
}
if (toolChain in VisualCpp) {
cppCompiler.args "/W0", "/EHsc"
}
}
all {
if(buildType == buildTypes.debug) {
cppCompiler.define "__DEBUG__"
if (toolChain in Gcc) {
cppCompiler.args "-Og", "-g3"
}
if (toolChain in Clang) {
cppCompiler.args "-O0", "-g"
}
if (toolChain in VisualCpp) {
cppCompiler.args "/Od", "/Z7"
}
}
if(buildType == buildTypes.release) {
cppCompiler.define "__NDEBUG__"
if (toolChain in Gcc) {
cppCompiler.args "-Ofast", "-g0"
}
if (toolChain in Clang) {
cppCompiler.args "-Ofast", "-g0"
}
if (toolChain in VisualCpp) {
cppCompiler.args "/O2"
}
}
}
}
}
Though when I run gradle build I get the following error:
Parallel execution is an incubating feature.
FAILURE: Build failed with an exception.
* What went wrong:
Could not determine the dependencies of task ':linkAnniReleaseExecutable'.
> No static library binary available for library 'openNN' with [flavor: 'default', platform: 'x64', buildType: 'release']
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.
* Get more help at https://help.gradle.org
BUILD FAILED in 1s
Can anyone help me with what I'm doing wrong?
(The repo can be found here and the version of the time of posting this question is: e518d77c4d)
I'm trying to follow https://selimober.com/gradle_unit_integration/
Using a slightly different file structure:
src/test/integration/groovy
src/test/unit/groovy
src/test/resources
Running "gradle integration" - the compile runs OK and class files appear in:
build/classes/integration
build/classes/main/
But the tests themselves are never run. I think I'm missing a section in dependencies or a linking of integration to running tests but can't figure out what I'm missing. Unless its that I have to change the file structure and have Test in the taskname like "integrationTest"
I've tried adding:
check.dependsOn integration
and
integrationCompile sourceSets.main.output
integrationCompile configurations.testCompile
integrationCompile sourceSets.test.output
integrationRuntime configurations.testRuntime
and
task integ(type: Test) {
testClassesDir = sourceSets.integ.output.classesDir
classpath = sourceSets.integ.runtimeClasspath
}
But that either hasn't changed anything or given me errors like:
Could not find method integrationCompile() for arguments [main classes] on object of type org.gradle.api.internal.artifacts.dsl.dependencies.DefaultDependencyHandler.
Thanks for any help.
My build.gradle file:
apply plugin: 'groovy'
repositories {
maven {
url repository_url
credentials {
username = artifactory_user
password = artifactory_password
}
}
}
dependencies {
compile(
'com.oracle:ojdbc6:11.2.0.1.0',
'javax.xml.bind:jsr173_api:1.0',
'org.apache.directory:groovy-ldap:1.0',
'org.codehaus.groovy:groovy-all:2.4.5',
'weblogic:wlfullclient:10.3.6',
'javax.jms:jms:1.1'
)
testCompile(
'junit:junit:4.12',
'org.spockframework:spock-core:1.0-groovy-2.4'
)
}
sourceSets {
unit {
groovy {
srcDir file('src/test/unit/groovy')
exclude '**/integration/**'
}
resources {
srcDir file('src/test/resources')
}
compileClasspath += sourceSets.main.output + sourceSets.test.output + configurations.testRuntime
runtimeClasspath += sourceSets.main.output + sourceSets.test.output + configurations.testRuntime
}
integration {
groovy {
srcDir 'src/test/integration/groovy'
exclude '**/unit/**'
}
resources {
srcDir 'src/test/resources'
}
compileClasspath += sourceSets.main.output + sourceSets.test.output + configurations.testRuntime
runtimeClasspath += sourceSets.main.output + sourceSets.test.output + configurations.testRuntime
}
}
configurations {
unitCompile.extendsFrom testCompile
unitRuntime.extendsFrom testRuntime
integrationCompile.extendsFrom testCompile
integrationRuntime.extendsFrom testRuntime
}
task unit(type: Test) {
include '**/unit/**'
testClassesDir = sourceSets.unit.output.classesDir
classpath = sourceSets.unit.runtimeClasspath
}
task integration(type: Test) {
include '**/integration/**'
testClassesDir = sourceSets.integration.output.classesDir
classpath = sourceSets.integration.runtimeClasspath
outputs.upToDateWhen { false }
}
The problem is in your includes in the tasks:
task unit(type: Test) {
include '**/unit/**'
}
task integration(type: Test) {
include '**/integration/**'
}
You don't need that, the folders are defined by the source sets. The includes cause the tests to be limited to classes whose package includes "unit" resp. "integration".
Delete that and your tests should run.
BTW you don't need these excludes neither:
sourceSets {
unit {
groovy {
exclude '**/integration/**'
}
}
}
Put your dependencies after source sets and configurations. Worked for me.
I'm trying to use Gradle to build the google-test example included in the samples folder with the download. On OS X and Linux it compiles correctly, but on Windows I get the error Plugin with id "google-test" not found.
My build.gradle file looks like this:
apply plugin: "cpp"
apply plugin: "google-test"
model {
flavors {
passing
failing
}
platforms {
x86 {
architecture "x86"
}
}
repositories {
libs(PrebuiltLibraries) {
googleTest {
headers.srcDir "libs/googleTest/1.7.0/include"
binaries.withType(StaticLibraryBinary) {
staticLibraryFile =
file("libs/googleTest/1.7.0/lib/" +
findGoogleTestCoreLibForPlatform(targetPlatform))
}
}
}
}
components {
operators(NativeLibrarySpec) {
targetPlatform "x86"
}
}
}
binaries.withType(GoogleTestTestSuiteBinarySpec) {
lib library: "googleTest", linkage: "static"
if (flavor == flavors.failing) {
cppCompiler.define "PLUS_BROKEN"
}
}
tasks.withType(RunTestExecutable) {
args "--gtest_output=xml:test_detail.xml"
}
def findGoogleTestCoreLibForPlatform(Platform platform) {
if (platform.operatingSystem.windows) {
return "vs2013/gtest.lib"
// return "vs2013/gtest-core.lib"
// return "cygwin/gtest-core.lib"
// return "mingw/gtest-core.lib"
} else if (platform.operatingSystem.macOsX) {
return "osx/libgtest.a"
} else {
return "linux/libgtest.a"
}
}
Any ideas on what could cause this?
Check the gradle version that you installed on windows/macosx. I'm not sure but I think the google-test plugin comes with version 2.5 rc
https://docs.gradle.org/release-candidate/release-notes#google-test-support
I want to make test of some clases in my project.
I'm project is all android, but the new clases are pure Java (I'm trying to make a little sdk for the app)
But I don't know how to configure correctly
Gradle file:
apply plugin: 'android'
android {
compileSdkVersion "Google Inc.:Google APIs:19"
buildToolsVersion "19.0.1"
lintOptions{
checkReleaseBuilds false
}
defaultConfig {
minSdkVersion 8
targetSdkVersion 19
versionCode 28
versionName "4.0.5"
}
signingConfigs {
debug {
..........
}
release {
..........
}
}
buildTypes {
debug{
runProguard false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
debuggable true
buildConfigField "boolean", "LOG_ENABLED", "true"
signingConfig signingConfigs.debug
}
release {
runProguard false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
debuggable false
buildConfigField "boolean", "LOG_ENABLED", "false"
signingConfig signingConfigs.release
}
}
productFlavors{
develFlavor{
}
testFlavor{
..........
}
trainingFlavor{
..........
}
preFlavor{
..........
}
proFlavor{
.........
}
}
}
if (project.hasProperty('storePassword')) {
android.signingConfigs.release.storePassword = storePassword
}
if (project.hasProperty('keyAlias')) {
android.signingConfigs.release.keyAlias = keyAlias
}
if (project.hasProperty('keyPassword')) {
android.signingConfigs.release.keyPassword = keyPassword
}
repositories {
mavenCentral()
}
sourceSets {
test {
java.srcDir file(''src/main/java/es/tempos/gas/sdk/test'')
}
}
dependencies {
unitTestCompile 'junit:junit:4.11'
compile 'com.google.code.gson:gson:1.7.1'
compile 'com.android.support:appcompat-v7:+'
compile files('libs/libGoogleAnalyticsServices.jar')
compile files('libs/sbc_mapslib.jar')
compile files('libs/t21c2dm-lib-v1.0.jar')
}
I want to put the test cases in the folfer Test>SDK
Estructure of the app:
+SmartPhoneGreatApp
----.idea
----app
-----build
-----libs
-----src
-----develFlavor
-----main
----sdk
-----preFlavor
----- .........
........
-----test
------sdk
and the testing class(for the moment do nothing)
package es.tempos21.gas.sdk.test;
import org.junit.Test;
public class AuthenticateTest {
#Test
public void testAuthenticate() throws Exception {
}
}
And the error I'm getting:
Gradle 'SmartPhoneGreatApp' project refresh failed:
Could not find property 'unitTest' on SourceSet container.
Gradle settings
In the Android plugin, sourceSets are configured differently from how the Java plugin does it, so you should read the docs at http://tools.android.com/tech-docs/new-build-system/user-guide#TOC-Sourcesets-and-Dependencies
For testing you'll want to do something like this:
android {
sourceSets {
androidTest.setRoot('tests')
}
}
A shortcut would be to do this instead:
android.sourceSets.androidTest.setRoot('tests')
Note that you're supplying a new top-level directory for where the tests go (and the Java classes will be in a directory structure underneath that corresponds to their package path); in your example you're trying to point it at a package already inside src/main/java/path/to/package, which isn't going to work.