Added jni/android implementation for trust cert chain
[platform/upstream/iotivity.git] / android / android_api / base / build.gradle
1 /*\r
2  *******************************************************************\r
3  *\r
4  * Copyright 2015 Intel Corporation.\r
5  *\r
6  *-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=\r
7  *\r
8  * Licensed under the Apache License, Version 2.0 (the "License");\r
9  * you may not use this file except in compliance with the License.\r
10  * You may obtain a copy of the License at\r
11  *\r
12  *      http://www.apache.org/licenses/LICENSE-2.0\r
13  *\r
14  * Unless required by applicable law or agreed to in writing, software\r
15  * distributed under the License is distributed on an "AS IS" BASIS,\r
16  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
17  * See the License for the specific language governing permissions and\r
18  * limitations under the License.\r
19  *\r
20  *-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=\r
21  */\r
22 \r
23 apply plugin: 'com.android.library'\r
24 \r
25 android {\r
26     compileSdkVersion 21\r
27     buildToolsVersion "20.0.0"\r
28     archivesBaseName = "iotivity-base"\r
29 \r
30     libraryVariants.all { variant ->\r
31         variant.outputs.each { output ->\r
32             def outputFile = output.outputFile\r
33             if (outputFile != null && outputFile.name.endsWith('.aar')) {\r
34                 def fileName = "${archivesBaseName}-${TARGET_ARCH}-${RELEASE}.aar"\r
35                 output.outputFile = new File(outputFile.parent, fileName)\r
36             }\r
37         }\r
38     }\r
39 \r
40     defaultConfig {\r
41         minSdkVersion 21\r
42         targetSdkVersion 21\r
43         versionCode 1\r
44         versionName "1.2.0"\r
45         buildConfigField 'int', 'SECURED', SECURED\r
46         buildConfigField 'int', 'WITH_TCP', WITH_TCP\r
47         buildConfigField 'int', 'WITH_CLOUD', WITH_CLOUD\r
48         buildConfigField "int", 'WITH_MQ_PUB', WITH_MQ_PUB\r
49         buildConfigField "int", 'WITH_MQ_SUB', WITH_MQ_SUB\r
50         buildConfigField "int", 'WITH_MQ_BROKER', WITH_MQ_BROKER\r
51         buildConfigField "String", 'RD_MODE', "\"RD_MODE\""\r
52         buildConfigField "int", 'WITH_TRANSPORT_EDR', WITH_TRANSPORT_EDR\r
53         buildConfigField "int", 'WITH_TRANSPORT_BLE', WITH_TRANSPORT_BLE\r
54         buildConfigField "int", 'WITH_TRANSPORT_NFC', WITH_TRANSPORT_NFC\r
55     }\r
56     buildTypes {\r
57         release {\r
58             proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'\r
59         }\r
60     }\r
61 \r
62     lintOptions {\r
63         abortOnError false\r
64     }\r
65 \r
66     sourceSets {\r
67         main {\r
68             manifest.srcFile 'src/main/AndroidManifest.xml'\r
69             jniLibs.srcDir 'libs'\r
70             jni.srcDirs = [] //disable automatic ndk-build call\r
71             java{\r
72                 if (WITH_TRANSPORT_EDR == "0") {\r
73                     exclude "**/ca/CaBtPairingInterface.java"\r
74                     exclude "**/ca/CaEdrInterface.java"\r
75                     println 'excluded EDR interface'\r
76                     }\r
77                 if (WITH_TRANSPORT_BLE == "0") {\r
78                     exclude "**/ca/CaLeClientInterface.java"\r
79                     exclude "**/ca/CaLeServerInterface.java"\r
80                     println 'excluded BLE interface'\r
81                     }\r
82                 if (WITH_TRANSPORT_NFC == "0") {\r
83                     exclude "**/ca/CaNfcInterface.java"\r
84                     println 'excluded NFC interface'\r
85                     }\r
86             }\r
87         }\r
88     }\r
89 }\r
90 \r
91 \r
92 dependencies {\r
93     compile fileTree(dir: 'libs', include: ['*.jar'])\r
94 }\r
95 \r
96 ////////////////\r
97 ////NDK Support\r
98 ////////////////\r
99 //If using this, Android studio will fail run the following to set the environment variable for android studio:\r
100 //launchctl setenv ANDROID_NDK_HOME /Users/boos_patrick/Development/Android/android-ndk-r8e\r
101 //otherwise remove the dependsOn part and run ./gradlew buildNative from the command line\r
102 \r
103 task copyNativeLibs(type: Copy, dependsOn: 'buildNative') {\r
104     dependsOn 'buildNative'\r
105     from(new File('libs')) { include '**/*.so' }\r
106     into new File(buildDir, 'native-libs')\r
107 }\r
108 \r
109 tasks.withType(JavaCompile) { compileTask -> compileTask.dependsOn copyNativeLibs }\r
110 \r
111 clean.dependsOn 'cleanCopyNativeLibs'\r
112 \r
113 tasks.withType(com.android.build.gradle.tasks.PackageApplication) { pkgTask ->\r
114     pkgTask.jniFolders = new HashSet<File>()\r
115     pkgTask.jniFolders.add(new File(buildDir, 'native-libs'))\r
116 }\r
117 \r
118 task buildNative(type: Exec) {\r
119     if (System.env.ANDROID_NDK_HOME != null) {\r
120         //for windows use 'ndk-build.cmd'\r
121         //def ndkBuild = new File(System.env.ANDROID_NDK_HOME, 'ndk-build.cmd')\r
122         def ndkBuild = new File(System.env.ANDROID_NDK_HOME, 'ndk-build')
123         commandLine ndkBuild, "APP_ABI=$TARGET_ARCH", "APP_OPTIM=$RELEASE", "SECURE=$SECURED", "WITH_CLOUD=$WITH_CLOUD", "RD_MODE=$RD_MODE", "WITH_MQ_PUB=$WITH_MQ_PUB", "WITH_MQ_SUB=$WITH_MQ_SUB", "WITH_MQ_BROKER=$WITH_MQ_BROKER", "WITH_TCP=$WITH_TCP"\r
124     } else {\r
125         println '##################'\r
126         println 'Skipping NDK build'\r
127         println 'Reason: ANDROID_NDK_HOME not set.'\r
128         println '##################'\r
129     }\r
130 }\r