Integrated the version info of IoTivity
[platform/upstream/iotivity.git] / java / iotivity-android / 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 \r
24 \r
25 buildscript {\r
26     repositories {\r
27         jcenter()\r
28     }\r
29     dependencies {\r
30         classpath 'com.android.tools.build:gradle:1.3.0'\r
31 \r
32         // NOTE: Do not place your application dependencies here; they belong\r
33         // in the individual module build.gradle files\r
34     }\r
35 }\r
36 \r
37 allprojects {\r
38     repositories {\r
39         jcenter()\r
40     }\r
41 }\r
42 \r
43 \r
44 apply plugin: 'com.android.library'\r
45     \r
46 android {\r
47     sourceSets {\r
48         main {\r
49             java {\r
50                 srcDirs 'src/main/java', '../common/src/main/java'\r
51             }\r
52             manifest.srcFile 'src/main/AndroidManifest.xml'\r
53             jniLibs.srcDir "$buildDir/native-libs"\r
54             jni.srcDirs = [] //disable automatic ndk-build call\r
55         }\r
56     }\r
57 \r
58     compileSdkVersion 21\r
59     buildToolsVersion "20.0.0"\r
60     archivesBaseName = "iotivity-base"\r
61 \r
62     libraryVariants.all { variant ->\r
63         variant.outputs.each { output ->\r
64             def outputFile = output.outputFile\r
65             if (outputFile != null && outputFile.name.endsWith('.aar')) {\r
66                 def fileName = "${archivesBaseName}-${TARGET_ARCH}-${RELEASE}.aar"\r
67                 output.outputFile = new File(outputFile.parent, fileName)\r
68             }\r
69         }\r
70     }\r
71 \r
72     defaultConfig {\r
73         minSdkVersion 21\r
74         targetSdkVersion 21\r
75         versionCode 1\r
76         versionName PROJECT_VERSION\r
77         buildConfigField 'int', 'SECURED', SECURED\r
78         buildConfigField 'int', 'WITH_TCP', WITH_TCP\r
79         buildConfigField 'int', 'WITH_CLOUD', WITH_CLOUD\r
80         buildConfigField "int", 'WITH_MQ_PUB', WITH_MQ_PUB\r
81         buildConfigField "int", 'WITH_MQ_SUB', WITH_MQ_SUB\r
82         buildConfigField "int", 'WITH_MQ_BROKER', WITH_MQ_BROKER\r
83         buildConfigField "String", 'RD_MODE', "\"RD_MODE\""\r
84         buildConfigField "int", 'WITH_TRANSPORT_EDR', WITH_TRANSPORT_EDR\r
85         buildConfigField "int", 'WITH_TRANSPORT_BLE', WITH_TRANSPORT_BLE\r
86         buildConfigField "int", 'WITH_TRANSPORT_NFC', WITH_TRANSPORT_NFC\r
87         buildConfigField "int", 'MULTIPLE_OWNER', MULTIPLE_OWNER\r
88     }\r
89     buildTypes {\r
90         release {\r
91             proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'\r
92         }\r
93     }\r
94 \r
95     lintOptions {\r
96         abortOnError false\r
97     }\r
98 \r
99     sourceSets {\r
100         main {\r
101             manifest.srcFile 'src/main/AndroidManifest.xml'\r
102             jniLibs.srcDir '$buildDir/native-libs'\r
103             jni.srcDirs = [] //disable automatic ndk-build call\r
104             java{\r
105                 if (WITH_TRANSPORT_EDR == "0") {\r
106                     exclude "**/ca/CaBtPairingInterface.java"\r
107                     exclude "**/ca/CaEdrInterface.java"\r
108                     println 'excluded EDR interface'\r
109                     }\r
110                 if (WITH_TRANSPORT_BLE == "0") {\r
111                     exclude "**/ca/CaLeClientInterface.java"\r
112                     exclude "**/ca/CaLeServerInterface.java"\r
113                     println 'excluded BLE interface'\r
114                     }\r
115                 if (WITH_TRANSPORT_NFC == "0") {\r
116                     exclude "**/ca/CaNfcInterface.java"\r
117                     println 'excluded NFC interface'\r
118                     }\r
119                 if (WITH_TCP == "0" || SECURED == "0") {\r
120                     exclude "**/base/OcCloudProvisioning.java"\r
121                     println 'excluded secure files'\r
122                     }\r
123             }\r
124         }\r
125     }\r
126 }\r
127 \r
128 dependencies {\r
129     compile fileTree(dir: 'libs', include: ['*.jar'])\r
130 }\r
131 \r
132 task copyNativeLibs(type: Copy) {\r
133     String[] libraries = [\r
134         'libgnustl_shared.so',\r
135         'libconnectivity_abstraction.so',\r
136         'libca-interface.so',\r
137         'liboc_logger.so',\r
138         'liboctbstack.so',\r
139         'liboc.so',\r
140         'libocstack-jni.so'\r
141     ]\r
142     if ("$SECURED" == '1')\r
143         libraries += [\r
144             'libocprovision.so',\r
145             'libocpmapi.so'\r
146         ]\r
147     from(new File("../../out/$TARGET_OS/$TARGET_ARCH/$RELEASE")) { include libraries }\r
148     into new File(buildDir, "native-libs/$TARGET_ARCH")\r
149 }\r
150 \r
151 tasks.withType(JavaCompile) { compileTask -> compileTask.dependsOn copyNativeLibs }\r
152 \r
153 tasks.withType(com.android.build.gradle.tasks.PackageApplication) { pkgTask ->\r
154     pkgTask.jniFolders = new HashSet<File>()\r
155     pkgTask.jniFolders.add(new File(buildDir, 'native-libs'))\r
156 }\r
157 \r
158 task buildNative(type: Exec) {\r
159     if (System.env.ANDROID_NDK_HOME != null) {\r
160         //for windows use 'ndk-build.cmd'\r
161         //def ndkBuild = new File(System.env.ANDROID_NDK_HOME, 'ndk-build.cmd')\r
162         def ndkBuild = new File(System.env.ANDROID_NDK_HOME, 'ndk-build')\r
163         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","MULTIPLE_OWNER=$MULTIPLE_OWNER"\r
164     } else {\r
165         println '##################'\r
166         println 'Skipping NDK build'\r
167         println 'Reason: ANDROID_NDK_HOME not set.'\r
168         println '##################'\r
169     }\r
170 }\r