Merge remote-tracking branch 'origin/extended-easysetup'
[platform/upstream/iotivity.git] / android / android_api / SConscript
1 import os
2 import platform
3 Import('env')
4
5 android_home = env.get('ANDROID_HOME')
6
7 ANDROID_TARGET_ARCH = env.get('TARGET_ARCH')
8 if env.get('RELEASE'):
9         ANDROID_RELEASE="release"
10 else:
11         ANDROID_RELEASE="debug"
12 ANDROID_SECURED = env.get('SECURED')
13 ANDROID_MQ = env.get('WITH_MQ')
14 ANDROID_MQ_SUB = 0
15 ANDROID_MQ_PUB = 0
16 ANDROID_MQ_BROKER = 0
17
18 if 'SUB' in ANDROID_MQ:
19         ANDROID_MQ_SUB = 1
20 if 'PUB' in ANDROID_MQ:
21         ANDROID_MQ_PUB = 1
22 if 'BROKER' in ANDROID_MQ:
23         ANDROID_MQ_BROKER = 1
24         
25 os.environ['ANDROID_HOME'] = env.get('ANDROID_HOME')
26 os.environ['ANDROID_NDK_HOME'] = env.get('ANDROID_NDK')
27
28 if not os.path.exists(android_home + '/platforms/android-21') or not os.path.exists(android_home + '/build-tools/20.0.0'):
29     print '''
30 ***************************************** Info ********************************
31 *   Either 'Android API 21' is not installed or 'Android SDK Build Tools      *
32 *   20.0.0' is not installed. The Android SDK Manager will now open. Please   *
33 *   be sure to deselect all options, then select the following 2 packages:    *
34 *       1. Under "Tools" select "Android SDK Build-tools" Revision 20.        *
35 *       2. Under "Android 5.0.1 (API 21)" select "SDK Platform"               *
36 *       3. Continue by selecting "Install 2 Packages"                         *
37 *                                                                             *
38 *   NOTE: If you have an http proxy, please press ctrl+c now and edit/create  *
39 *         the following file in your $HOME directory as follows:              *
40 *                                                                             *
41 * Edit/Create file: "$HOME/.android/androidtool.cfg"                          *
42 *                                                                             *
43 *    http.proxyPort=<YOUR_PORT_NUMBER>                                        *
44 *    sdkman.monitor.density=108                                               *
45 *    http.proxyHost=<YOUR_HTTP_PROXY_ADDRESS>                                 *
46 *    sdkman.show.update.only=true                                             *
47 *    sdkman.ask.adb.restart=false                                             *
48 *    sdkman.force.http=true                                                   *
49 *    sdkman.show.updateonly=true                                              *
50 *                                                                             *
51 *******************************************************************************
52
53 ...Opening Android SDK Manager now. Once you are finished, the build will continue.
54 '''
55     os.system(android_home + '/tools/android')
56
57 def ensure_libs(target, source, env):
58     return target, [source, env.get('BUILD_DIR') + 'liboc.so', env.get('BUILD_DIR') + 'liboc_logger.so']
59
60 # build android_api
61 jdk_env = Environment(ENV=os.environ)
62 jdk_env['BUILDERS']['Gradle'] = Builder(action = env.get('ANDROID_GRADLE') + ' build -b' + os.getcwd()+'/build.gradle -PTARGET_ARCH=%s -PRELEASE=%s -PSECURED=%s -DSECURE=%s -PWITH_MQ_PUB=%s -PWITH_MQ_SUB=%s -PWITH_MQ_BROKER=%s --stacktrace' %(ANDROID_TARGET_ARCH, ANDROID_RELEASE, ANDROID_SECURED, ANDROID_SECURED, ANDROID_MQ_PUB, ANDROID_MQ_SUB, ANDROID_MQ_BROKER), emitter = ensure_libs)
63 jdk_env['BUILD_DIR'] = env.get('BUILD_DIR')
64 cmdBuildApi=jdk_env.Gradle(target="base/objs", source="base/src/main/java/org/iotivity/base/OcResource.java")
65
66 jdk_env['BUILDERS']['Gradle'] = Builder(action = env.get('ANDROID_GRADLE') + ' build -b' + 'android/examples/build.gradle -PTARGET_ARCH=%s -PRELEASE=%s -PSECURED=%s -DSECURE=%s -PWITH_MQ_PUB=%s -PWITH_MQ_SUB=%s -PWITH_MQ_BROKER=%s --stacktrace' %(ANDROID_TARGET_ARCH, ANDROID_RELEASE, ANDROID_SECURED, ANDROID_SECURED, ANDROID_MQ_PUB, ANDROID_MQ_SUB, ANDROID_MQ_BROKER))
67 cmdBuildExamples=jdk_env.Gradle(target="../examples/devicediscoveryclient/apk", source="../examples/devicediscoveryclient/src/main/java/org/iotivity/base/examples/DeviceDiscoveryClient.java")
68
69 # android examples require android api to be built before being invoked
70 Depends(cmdBuildExamples, cmdBuildApi)
71
72 env.AppendUnique(baseAAR = cmdBuildApi)