[IOT-1089] Change Android build system to accomodate both Android and Generic Java...
[contrib/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 "1.0"\r
77     }\r
78     buildTypes {\r
79         release {\r
80             proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'\r
81         }\r
82     }\r
83 \r
84     lintOptions {\r
85         abortOnError false\r
86     }\r
87 \r
88 }\r
89 \r
90 dependencies {\r
91     compile fileTree(dir: 'libs', include: ['*.jar'])\r
92 }\r
93 \r
94 task copyNativeLibs(type: Copy) {\r
95     String[] libraries = [\r
96         'libca-interface.so',\r
97         'libconnectivity_abstraction.so',\r
98         'libgnustl_shared.so',\r
99         'liboc_logger.so',\r
100         'liboc.so',\r
101         'libocstack-jni.so',\r
102         'liboctbstack.so'\r
103     ]\r
104     if ("$SECURED" == '1')\r
105         libraries += [\r
106             'libocprovision.so',\r
107             'libocpmapi.so'\r
108         ]\r
109     from(new File("$BUILD_DIR")) { include libraries }\r
110     into new File(buildDir, "native-libs/$TARGET_ARCH")\r
111 }\r
112 \r
113 tasks.withType(JavaCompile) { compileTask -> compileTask.dependsOn copyNativeLibs }\r
114 \r
115 tasks.withType(com.android.build.gradle.tasks.PackageApplication) { pkgTask ->\r
116     pkgTask.jniFolders = new HashSet<File>()\r
117     pkgTask.jniFolders.add(new File(buildDir, 'native-libs'))\r
118 }\r