1 apply plugin: 'com.android.library'
2 // Top-level build file where you can add configuration options common to all sub-projects/modules.
6 buildToolsVersion '20.0.0'
7 archivesBaseName = "iotivity"
9 libraryVariants.all { variant ->
10 variant.outputs.each { output ->
11 def outputFile = output.outputFile
12 if (outputFile != null && outputFile.name.endsWith('.aar')) {
13 def fileName = "${outputFile.name}"
14 output.outputFile = new File(outputFile.parent, fileName)
28 dirs '../../../../../../android/android_api/base/build/outputs/aar'
35 proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
44 manifest.srcFile 'src/main/AndroidManifest.xml'
45 jni.srcDirs = [] //disable automatic ndk-build call
46 jniLibs.srcDir new File(buildDir, 'native-libs')
48 //androidTest.setRoot('src/androidTest')
53 compile ":iotivity-base-${TARGET_ARCH}-${RELEASE}@aar"
54 androidTestCompile 'com.google.dexmaker:dexmaker-mockito:1.0'
55 androidTestCompile 'com.google.dexmaker:dexmaker:1.0'
56 androidTestCompile 'org.mockito:mockito-core:1.10.19'
62 //If using this, Android studio will fail run the following to set the environment variable for android studio:
63 //launchctl setenv ANDROID_NDK_HOME
64 //otherwise remove the dependsOn part and run ./gradlew buildNative from the command line
65 task copyNativeLibs(type: Copy, dependsOn: 'buildNative') {
66 dependsOn 'buildNative'
67 from(new File('src/main/libs/armeabi')) { include '**/*.so' exclude '**/libgnustl_shared.so', '**/liboc.so', '**/libocstack-jni.so'}
68 into new File(buildDir, 'native-libs/armeabi')
71 tasks.withType(JavaCompile) { compileTask -> compileTask.dependsOn copyNativeLibs }
73 clean.dependsOn 'cleanCopyNativeLibs'
75 tasks.withType(com.android.build.gradle.tasks.PackageApplication) {
77 pkgTask.jniFolders = new HashSet<File>()
78 pkgTask.jniFolders.add(new File(buildDir, 'native-libs'))
81 task buildNative(type: Exec) {
82 if (System.env.ANDROID_NDK_HOME != null) {
83 //for windows use 'ndk-build.cmd'
84 //def ndkBuild = new File(System.env.ANDROID_NDK_HOME, 'ndk-build.cmd')
85 def ndkBuild = new File(System.env.ANDROID_NDK_HOME, 'ndk-build')
86 commandLine ndkBuild, "APP_ABI=$TARGET_ARCH", "APP_OPTIM=$RELEASE", '-C', file('src/main').absolutePath
88 println '##################'
89 println 'Skipping NDK build'
90 println 'Reason: ANDROID_NDK_HOME not set.'
91 println '##################'