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 "20.0.0"
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 dirs '../../../../android/android_api/base/build/outputs/aar'
51 proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
61 manifest.srcFile 'src/main/AndroidManifest.xml'
62 jni.srcDirs = [] //disable automatic ndk-build call
63 jniLibs.srcDir new File(buildDir, 'native-libs')
65 androidTest.setRoot('src/androidTest')
71 compile fileTree(dir: 'libs', include: ['*.jar'])
72 compile ":iotivity-base-${TARGET_ARCH}-${RELEASE}@aar"
73 androidTestCompile 'com.google.dexmaker:dexmaker-mockito:1.0'
74 androidTestCompile 'com.google.dexmaker:dexmaker:1.0'
75 androidTestCompile 'org.mockito:mockito-core:1.10.19'
81 //If using this, Android studio will fail run the following to set the environment variable for android studio:
82 //launchctl setenv ANDROID_NDK_HOME
83 //otherwise remove the dependsOn part and run ./gradlew buildNative from the command line
84 task copyNativeLibs(type: Copy, dependsOn: 'buildNative') {
85 dependsOn 'buildNative'
86 from(new File('src/main/libs')) { include '**/*.so' exclude '**/libgnustl_shared.so' }
87 into new File(buildDir, 'native-libs')
90 tasks.withType(JavaCompile) { compileTask -> compileTask.dependsOn copyNativeLibs }
92 clean.dependsOn 'cleanCopyNativeLibs'
94 tasks.withType(com.android.build.gradle.tasks.PackageApplication) {
96 pkgTask.jniFolders = new HashSet<File>()
97 pkgTask.jniFolders.add(new File(buildDir, 'native-libs'))
100 task buildNative(type: Exec) {
101 if (System.env.ANDROID_NDK_HOME != null) {
102 //for windows use 'ndk-build.cmd'
103 //def ndkBuild = new File(System.env.ANDROID_NDK_HOME, 'ndk-build.cmd')
104 def ndkBuild = new File(System.env.ANDROID_NDK_HOME, 'ndk-build')
105 commandLine ndkBuild, "APP_ABI=$TARGET_ARCH", "APP_OPTIM=$RELEASE", '-C', file('src/main').absolutePath
107 println '##################'
108 println 'Skipping NDK build'
109 println 'Reason: ANDROID_NDK_HOME not set.'
110 println '##################'