Imported Upstream version 1.1.0
[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
14 os.environ['ANDROID_HOME'] = env.get('ANDROID_HOME')
15 os.environ['ANDROID_NDK_HOME'] = env.get('ANDROID_NDK')
16
17 if not os.path.exists(android_home + '/platforms/android-21') or not os.path.exists(android_home + '/build-tools/20.0.0'):
18     print '''
19 ***************************************** Info ********************************
20 *   Either 'Android API 21' is not installed or 'Android SDK Build Tools      *
21 *   20.0.0' is not installed. The Android SDK Manager will now open. Please   *
22 *   be sure to deselect all options, then select the following 2 packages:    *
23 *       1. Under "Tools" select "Android SDK Build-tools" Revision 20.        *
24 *       2. Under "Android 5.0.1 (API 21)" select "SDK Platform"               *
25 *       3. Continue by selecting "Install 2 Packages"                         *
26 *                                                                             *
27 *   NOTE: If you have an http proxy, please press ctrl+c now and edit/create  *
28 *         the following file in your $HOME directory as follows:              *
29 *                                                                             *
30 * Edit/Create file: "$HOME/.android/androidtool.cfg"                          *
31 *                                                                             *
32 *    http.proxyPort=<YOUR_PORT_NUMBER>                                        *
33 *    sdkman.monitor.density=108                                               *
34 *    http.proxyHost=<YOUR_HTTP_PROXY_ADDRESS>                                 *
35 *    sdkman.show.update.only=true                                             *
36 *    sdkman.ask.adb.restart=false                                             *
37 *    sdkman.force.http=true                                                   *
38 *    sdkman.show.updateonly=true                                              *
39 *                                                                             *
40 *******************************************************************************
41
42 ...Opening Android SDK Manager now. Once you are finished, the build will continue.
43 '''
44     os.system(android_home + '/tools/android')
45
46 def ensure_libs(target, source, env):
47     return target, [source, env.get('BUILD_DIR') + 'liboc.so', env.get('BUILD_DIR') + 'liboc_logger.so']
48
49 # build android_api
50 jdk_env = Environment(ENV=os.environ)
51 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 --stacktrace' %(ANDROID_TARGET_ARCH, ANDROID_RELEASE, ANDROID_SECURED, ANDROID_SECURED), emitter = ensure_libs)
52 jdk_env['BUILD_DIR'] = env.get('BUILD_DIR')
53 cmdBuildApi=jdk_env.Gradle(target="base/objs", source="base/src/main/java/org/iotivity/base/OcResource.java")
54
55 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 --stacktrace' %(ANDROID_TARGET_ARCH, ANDROID_RELEASE, ANDROID_SECURED, ANDROID_SECURED))
56 cmdBuildExamples=jdk_env.Gradle(target="../examples/devicediscoveryclient/apk", source="../examples/devicediscoveryclient/src/main/java/org/iotivity/base/examples/DeviceDiscoveryClient.java")
57
58 # android examples require android api to be built before being invoked
59 Depends(cmdBuildExamples, cmdBuildApi)
60