1 /******************************************************************
3 * Copyright 2015 Samsung Electronics All Rights Reserved.
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
19 ******************************************************************/
21 apply plugin: 'com.android.library'
25 buildToolsVersion "23.0.1"
26 archivesBaseName = "iotivity"
28 libraryVariants.all { variant ->
29 variant.outputs.each { output ->
30 def outputFile = output.outputFile
31 if (outputFile != null && outputFile.name.endsWith('.aar')) {
32 def fileName = "${archivesBaseName}-${TARGET_ARCH}-${outputFile.name}"
33 output.outputFile = new File(outputFile.parent, fileName)
46 proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
56 manifest.srcFile 'src/main/AndroidManifest.xml'
57 jni.srcDirs = [] //disable automatic ndk-build call
58 jniLibs.srcDir new File(buildDir, 'native-libs')
60 androidTest.setRoot('src/androidTest')
66 compile fileTree(dir: 'libs', include: ['*.jar'])
68 androidTestCompile 'com.google.dexmaker:dexmaker-mockito:1.0'
69 androidTestCompile 'com.google.dexmaker:dexmaker:1.0'
70 androidTestCompile 'org.mockito:mockito-core:1.10.19'
76 //If using this, Android studio will fail run the following to set the environment variable for android studio:
77 //launchctl setenv ANDROID_NDK_HOME
78 //otherwise remove the dependsOn part and run ./gradlew buildNative from the command line
79 task copyNativeLibs(type: Copy, dependsOn: 'buildNative') {
80 dependsOn 'buildNative'
81 from(new File('src/main/libs')) { include '**/*.so' exclude '**/libgnustl_shared.so' }
82 into new File(buildDir, 'native-libs')
85 tasks.withType(JavaCompile) { compileTask -> compileTask.dependsOn copyNativeLibs }
87 clean.dependsOn 'cleanCopyNativeLibs'
89 tasks.withType(com.android.build.gradle.tasks.PackageApplication) {
91 pkgTask.jniFolders = new HashSet<File>()
92 pkgTask.jniFolders.add(new File(buildDir, 'native-libs'))
95 task buildNative(type: Exec) {
96 if (System.env.ANDROID_NDK_HOME != null) {
97 //for windows use 'ndk-build.cmd'
98 //def ndkBuild = new File(System.env.ANDROID_NDK_HOME, 'ndk-build.cmd')
99 def ndkBuild = new File(System.env.ANDROID_NDK_HOME, 'ndk-build')
100 commandLine ndkBuild, "APP_ABI=$TARGET_ARCH", "APP_OPTIM=$RELEASE", '-C', file('src/main').absolutePath
102 println '##################'
103 println 'Skipping NDK build'
104 println 'Reason: ANDROID_NDK_HOME not set.'
105 println '##################'