Merge remote-tracking branch 'origin/extended-easysetup'
[platform/upstream/iotivity.git] / service / easy-setup / mediator / richsdk / android / EasySetupCore / build.gradle
1 apply plugin: 'com.android.library'
2 // Top-level build file where you can add configuration options common to all sub-projects/modules.
3
4 android {
5     compileSdkVersion 21
6     buildToolsVersion '20.0.0'
7     archivesBaseName = "iotivity"
8
9     libraryVariants.all { variant ->
10         variant.outputs.each { output ->
11             def outputFile = output.outputFile
12             if (outputFile != null && outputFile.name.endsWith('.aar')) {
13                 def fileName = "${outputFile.name}"
14                 output.outputFile = new File(outputFile.parent, fileName)
15             }
16         }
17     }
18     
19     defaultConfig {
20         minSdkVersion 21
21         targetSdkVersion 21
22         versionCode 1
23         versionName "1.0"
24     }
25
26     repositories {        
27         flatDir {
28             dirs '../../../../../../android/android_api/base/build/outputs/aar'
29         }
30     }
31
32     buildTypes {
33         release {
34             minifyEnabled false
35             proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
36         }
37     }
38     
39     lintOptions {
40        abortOnError false
41     }
42     sourceSets {
43         main {
44             manifest.srcFile 'src/main/AndroidManifest.xml'
45             jni.srcDirs = [] //disable automatic ndk-build call
46             jniLibs.srcDir new File(buildDir, 'native-libs')
47         }
48         //androidTest.setRoot('src/androidTest')        
49     }
50 }
51
52 dependencies {
53     compile ":iotivity-base-${TARGET_ARCH}-${RELEASE}@aar"
54     androidTestCompile 'com.google.dexmaker:dexmaker-mockito:1.0'
55     androidTestCompile 'com.google.dexmaker:dexmaker:1.0'
56     androidTestCompile 'org.mockito:mockito-core:1.10.19'
57 }
58
59 ////////////////
60 ////NDK Support
61 ////////////////
62 //If using this, Android studio will fail run the following to set the environment variable for android studio:
63 //launchctl setenv ANDROID_NDK_HOME
64 //otherwise remove the dependsOn part and run ./gradlew buildNative from the command line
65 task copyNativeLibs(type: Copy, dependsOn: 'buildNative') {
66     dependsOn 'buildNative'
67     from(new File('src/main/libs/armeabi')) { include '**/*.so' exclude '**/libgnustl_shared.so', '**/liboc.so', '**/libocstack-jni.so'}
68     into new File(buildDir, 'native-libs/armeabi')
69 }
70
71 tasks.withType(JavaCompile) { compileTask -> compileTask.dependsOn copyNativeLibs }
72
73 clean.dependsOn 'cleanCopyNativeLibs'
74
75 tasks.withType(com.android.build.gradle.tasks.PackageApplication) {
76     pkgTask ->
77     pkgTask.jniFolders = new HashSet<File>()
78     pkgTask.jniFolders.add(new File(buildDir, 'native-libs'))
79 }
80
81 task buildNative(type: Exec) {
82     if (System.env.ANDROID_NDK_HOME != null) {
83         //for windows use 'ndk-build.cmd'
84         //def ndkBuild = new File(System.env.ANDROID_NDK_HOME, 'ndk-build.cmd')
85         def ndkBuild = new File(System.env.ANDROID_NDK_HOME, 'ndk-build')
86         commandLine ndkBuild, "APP_ABI=$TARGET_ARCH", "APP_OPTIM=$RELEASE", '-C', file('src/main').absolutePath
87     } else {
88         println '##################'
89         println 'Skipping NDK build'
90         println 'Reason: ANDROID_NDK_HOME not set.'
91         println '##################'
92     }
93 }