RC android: load bundle classes from library
[platform/upstream/iotivity.git] / service / resource-container / android / resource-container / build.gradle
1 /******************************************************************
2  *
3  * Copyright 2015 Samsung Electronics All Rights Reserved.
4  *
5  *
6  *
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
10  *
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  *
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.
18  *
19  ******************************************************************/
20
21 apply plugin: 'com.android.library'
22
23 task jar(type: Jar) {
24     from fileTree(dir: 'build/intermediates/classes/release')
25 }
26
27 android {
28     compileSdkVersion 21
29     buildToolsVersion "20.0.0"
30     archivesBaseName = "iotivity"
31
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)
38             }
39         }
40     }
41
42     defaultConfig {
43         minSdkVersion 21
44         targetSdkVersion 21
45         versionCode 1
46         versionName "1.0"
47     }
48     buildTypes {
49         release {
50             proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
51         }
52     }
53
54     lintOptions {
55        abortOnError false
56     }
57
58     sourceSets {
59         main {
60             manifest.srcFile 'src/main/AndroidManifest.xml'
61             jni.srcDirs = [] //disable automatic ndk-build call
62             jniLibs.srcDir new File(buildDir, 'native-libs')
63         }
64         androidTest.setRoot('src/androidTest')
65     }
66 }
67
68
69 dependencies {
70     compile fileTree(dir: 'libs', include: ['*.jar'])
71
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'
75 }
76
77 ////////////////
78 ////NDK Support
79 ////////////////
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')
87 }
88
89 tasks.withType(JavaCompile) { compileTask -> compileTask.dependsOn copyNativeLibs }
90
91 clean.dependsOn 'cleanCopyNativeLibs'
92
93 tasks.withType(com.android.build.gradle.tasks.PackageApplication) {
94     pkgTask ->
95     pkgTask.jniFolders = new HashSet<File>()
96     pkgTask.jniFolders.add(new File(buildDir, 'native-libs'))
97 }
98
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
105     } else {
106         println '##################'
107         println 'Skipping NDK build'
108         println 'Reason: ANDROID_NDK_HOME not set.'
109         println '##################'
110     }
111 }