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'
24 from fileTree(dir: 'build/intermediates/classes/release')
29 buildToolsVersion "20.0.0"
30 archivesBaseName = "iotivity"
32 libraryVariants.all { variant ->
33 variant.outputs.each { output ->
34 def outputFile = output.outputFile
35 if (outputFile != null && outputFile.name.endsWith('.aar')) {
36 def fileName = "${archivesBaseName}-${TARGET_ARCH}-${outputFile.name}"
37 output.outputFile = new File(outputFile.parent, fileName)
50 proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
60 manifest.srcFile 'src/main/AndroidManifest.xml'
61 jni.srcDirs = [] //disable automatic ndk-build call
62 jniLibs.srcDir new File(buildDir, 'native-libs')
64 androidTest.setRoot('src/androidTest')
70 compile fileTree(dir: 'libs', include: ['*.jar'])
72 androidTestCompile 'com.google.dexmaker:dexmaker-mockito:1.0'
73 androidTestCompile 'com.google.dexmaker:dexmaker:1.0'
74 androidTestCompile 'org.mockito:mockito-core:1.10.19'
80 //If using this, Android studio will fail run the following to set the environment variable for android studio:
81 //launchctl setenv ANDROID_NDK_HOME
82 //otherwise remove the dependsOn part and run ./gradlew buildNative from the command line
83 task copyNativeLibs(type: Copy, dependsOn: 'buildNative') {
84 dependsOn 'buildNative'
85 from(new File('src/main/libs')) { include '**/*.so' exclude '**/libgnustl_shared.so' }
86 into new File(buildDir, 'native-libs')
89 tasks.withType(JavaCompile) { compileTask -> compileTask.dependsOn copyNativeLibs }
91 clean.dependsOn 'cleanCopyNativeLibs'
93 tasks.withType(com.android.build.gradle.tasks.PackageApplication) {
95 pkgTask.jniFolders = new HashSet<File>()
96 pkgTask.jniFolders.add(new File(buildDir, 'native-libs'))
99 task buildNative(type: Exec) {
100 if (System.env.ANDROID_NDK_HOME != null) {
101 //for windows use 'ndk-build.cmd'
102 //def ndkBuild = new File(System.env.ANDROID_NDK_HOME, 'ndk-build.cmd')
103 def ndkBuild = new File(System.env.ANDROID_NDK_HOME, 'ndk-build')
104 commandLine ndkBuild, "V=1", "APP_ABI=$TARGET_ARCH", "APP_OPTIM=$RELEASE", '-C', file('src/main').absolutePath
106 println '##################'
107 println 'Skipping NDK build'
108 println 'Reason: ANDROID_NDK_HOME not set.'
109 println '##################'