2013-04-18 01:46:47 +02:00
#!/usr/bin/python
2013-04-22 21:37:13 +02:00
import lutinDebug as debug
import lutinTarget
import lutinTools
2013-07-10 09:21:53 +02:00
import lutinHost
2014-05-11 16:12:55 +02:00
import lutinImage
2013-07-11 13:53:19 +02:00
import lutinMultiprocess
2013-04-22 21:37:13 +02:00
import os
2014-04-06 18:39:47 +02:00
import sys
2013-04-22 21:37:13 +02:00
class Target ( lutinTarget . Target ) :
2014-04-22 23:33:07 +02:00
def __init__ ( self , typeCompilator , debugMode , generatePackage , sumulator = False ) :
2013-04-22 21:37:13 +02:00
2013-09-03 21:27:08 +02:00
self . folder_ndk = os . getenv ( ' PROJECT_NDK ' , " AUTO " )
self . folder_sdk = os . getenv ( ' PROJECT_SDK ' , " AUTO " )
# auto search NDK
if self . folder_ndk == " AUTO " :
for folder in os . listdir ( " . " ) :
if os . path . isdir ( folder ) == True :
if folder == " android " :
self . folder_ndk = folder + " /ndk "
if self . folder_ndk == " AUTO " :
2013-12-23 22:22:24 +01:00
self . folder_ndk = lutinTools . get_run_folder ( ) + " /../android/ndk "
2013-09-03 21:27:08 +02:00
# auto search SDK
if self . folder_sdk == " AUTO " :
for folder in os . listdir ( " . " ) :
if os . path . isdir ( folder ) == True :
if folder == " android " :
self . folder_sdk = folder + " /sdk "
if self . folder_sdk == " AUTO " :
2013-12-23 22:22:24 +01:00
self . folder_sdk = lutinTools . get_run_folder ( ) + " /../android/sdk "
2013-09-03 21:27:08 +02:00
2014-06-18 14:56:53 +02:00
if not os . path . isdir ( self . folder_ndk ) :
debug . error ( " NDK path not set !!! set env : PROJECT_NDK on the NDK path " )
if not os . path . isdir ( self . folder_sdk ) :
debug . error ( " SDK path not set !!! set env : PROJECT_SDK on the SDK path " )
2014-05-11 16:12:55 +02:00
arch = " " #"ARMv7"
2013-11-06 21:13:30 +01:00
tmpOsVal = " 64 "
gccVersion = " 4.8 "
2013-07-10 09:21:53 +02:00
if lutinHost . OS64BITS == True :
2013-11-06 21:13:30 +01:00
tmpOsVal = " _64 "
2013-11-11 20:15:52 +01:00
if typeCompilator == " clang " :
cross = self . folder_ndk + " /toolchains/llvm-3.3/prebuilt/linux-x86_64/bin/ "
else :
baseFolderArm = self . folder_ndk + " /toolchains/arm-linux-androideabi- " + gccVersion + " /prebuilt/linux-x86 " + tmpOsVal + " /bin/ "
baseFolderMips = self . folder_ndk + " /toolchains/mipsel-linux-android- " + gccVersion + " /prebuilt/linux-x86 " + tmpOsVal + " /bin/ "
baseFolderX86 = self . folder_ndk + " /toolchains/x86- " + gccVersion + " /prebuilt/linux-x86 " + tmpOsVal + " /bin/ "
cross = baseFolderArm + " arm-linux-androideabi- "
if not os . path . isdir ( baseFolderArm ) :
2014-06-18 14:56:53 +02:00
debug . error ( " Gcc Arm path does not exist !!! " )
2013-11-11 20:15:52 +01:00
if not os . path . isdir ( baseFolderMips ) :
2014-06-18 14:56:53 +02:00
debug . info ( " Gcc Mips path does not exist !!! " )
2013-11-11 20:15:52 +01:00
if not os . path . isdir ( baseFolderX86 ) :
2014-06-18 14:56:53 +02:00
debug . info ( " Gcc x86 path does not exist !!! " )
2013-11-11 20:15:52 +01:00
2014-04-22 23:33:07 +02:00
lutinTarget . Target . __init__ ( self , " Android " , typeCompilator , debugMode , generatePackage , arch , cross , sumulator )
2014-05-11 16:12:55 +02:00
arch = " ARMv7 "
2013-11-11 20:15:52 +01:00
# for gcc :
2013-04-22 21:37:13 +02:00
2013-11-11 20:15:52 +01:00
# for clang :
2013-04-22 21:37:13 +02:00
2013-04-23 21:48:36 +02:00
self . folder_bin = " /mustNotCreateBinary "
self . folder_lib = " /data/lib/armeabi "
self . folder_data = " /data/assets "
self . folder_doc = " /doc "
self . suffix_package = ' .pkg '
# board id at 14 is for android 4.0 and more ...
2013-04-22 21:37:13 +02:00
self . boardId = 14
2013-11-20 21:26:31 +01:00
if arch == " ARMv5 " or arch == " ARMv7 " :
self . global_include_cc . append ( " -I " + self . folder_ndk + " /platforms/android- " + str ( self . boardId ) + " /arch-arm/usr/include/ " )
elif arch == " mips " :
self . global_include_cc . append ( " -I " + self . folder_ndk + " /platforms/android- " + str ( self . boardId ) + " /arch-mips/usr/include/ " )
elif arch == " x86 " :
self . global_include_cc . append ( " -I " + self . folder_ndk + " /platforms/android- " + str ( self . boardId ) + " /arch-x86/usr/include/ " )
2013-11-11 20:15:52 +01:00
if True :
if typeCompilator == " clang " :
self . global_include_cc . append ( " -I " + self . folder_ndk + " /sources/cxx-stl/llvm-libc++/libcxx/include/ " )
2013-11-20 21:26:31 +01:00
if arch == " ARMv5 " :
stdCppBasePath = self . folder_ndk + " /sources/cxx-stl/llvm-libc++/libcxx/libs/armeabi/ "
self . global_include_cc . append ( " -I " + stdCppBasePath + " include/ " )
self . global_flags_ld . append ( stdCppBasePath + " libc++_static.a " )
elif arch == " ARMv7 " :
stdCppBasePath = self . folder_ndk + " /sources/cxx-stl/llvm-libc++/libcxx/libs/armeabi-v7a/ "
self . global_include_cc . append ( " -I " + stdCppBasePath + " include/ " )
self . global_flags_ld . append ( stdCppBasePath + " libc++_static.a " )
elif arch == " mips " :
stdCppBasePath = self . folder_ndk + " /sources/cxx-stl/llvm-libc++/libcxx/libs/mips/ "
self . global_include_cc . append ( " -I " + stdCppBasePath + " include/ " )
self . global_flags_ld . append ( stdCppBasePath + " libc++_static.a " )
elif arch == " x86 " :
stdCppBasePath = self . folder_ndk + " /sources/cxx-stl/llvm-libc++/libcxx/libs/x86/ "
self . global_include_cc . append ( " -I " + stdCppBasePath + " include/ " )
self . global_flags_ld . append ( stdCppBasePath + " libc++_static.a " )
2013-11-11 20:15:52 +01:00
else :
self . global_include_cc . append ( " -I " + self . folder_ndk + " /sources/cxx-stl/gnu-libstdc++/ " + gccVersion + " /include/ " )
2013-11-20 21:26:31 +01:00
if arch == " ARMv5 " :
stdCppBasePath = self . folder_ndk + " /sources/cxx-stl/gnu-libstdc++/ " + gccVersion + " /libs/armeabi/ "
self . global_include_cc . append ( " -I " + stdCppBasePath + " include/ " )
self . global_flags_ld . append ( stdCppBasePath + " thumb/libgnustl_static.a " )
self . global_flags_ld . append ( stdCppBasePath + " thumb/libsupc++.a " )
elif arch == " ARMv7 " :
stdCppBasePath = self . folder_ndk + " /sources/cxx-stl/gnu-libstdc++/ " + gccVersion + " /libs/armeabi-v7a/ "
self . global_include_cc . append ( " -I " + stdCppBasePath + " include/ " )
self . global_flags_ld . append ( stdCppBasePath + " thumb/libgnustl_static.a " )
self . global_flags_ld . append ( stdCppBasePath + " thumb/libsupc++.a " )
elif arch == " mips " :
stdCppBasePath = self . folder_ndk + " /sources/cxx-stl/gnu-libstdc++/ " + gccVersion + " /libs/mips/ "
self . global_include_cc . append ( " -I " + stdCppBasePath + " include/ " )
self . global_flags_ld . append ( stdCppBasePath + " libgnustl_static.a " )
self . global_flags_ld . append ( stdCppBasePath + " libsupc++.a " )
elif arch == " x86 " :
stdCppBasePath = self . folder_ndk + " /sources/cxx-stl/gnu-libstdc++/ " + gccVersion + " /libs/x86/ "
self . global_include_cc . append ( " -I " + stdCppBasePath + " include/ " )
self . global_flags_ld . append ( stdCppBasePath + " libgnustl_static.a " )
self . global_flags_ld . append ( stdCppBasePath + " libsupc++.a " )
2013-11-11 20:15:52 +01:00
else :
2013-11-20 21:26:31 +01:00
self . global_include_cc . append ( " -I " + self . folder_ndk + " /sources/cxx-stl/system/include/ " )
2013-11-11 20:15:52 +01:00
self . global_include_cc . append ( " -I " + self . folder_ndk + " /sources/cxx-stl/stlport/stlport/ " )
self . global_flags_ld . append ( self . folder_ndk + " /platforms/android- " + str ( self . boardId ) + " /arch-arm/usr/lib/libstdc++.a " )
2013-04-22 21:37:13 +02:00
self . global_sysroot = " --sysroot= " + self . folder_ndk + " /platforms/android- " + str ( self . boardId ) + " /arch-arm "
self . global_flags_cc . append ( " -D__ARM_ARCH_5__ " )
self . global_flags_cc . append ( " -D__ARM_ARCH_5T__ " )
self . global_flags_cc . append ( " -D__ARM_ARCH_5E__ " )
self . global_flags_cc . append ( " -D__ARM_ARCH_5TE__ " )
if self . arch == " ARM " :
# -----------------------
# -- arm V5 :
# -----------------------
self . global_flags_cc . append ( " -march=armv5te " )
self . global_flags_cc . append ( " -msoft-float " )
else :
# -----------------------
# -- arm V7 (Neon) :
# -----------------------
self . global_flags_cc . append ( " -mfpu=neon " )
self . global_flags_cc . append ( " -mfloat-abi=softfp " )
self . global_flags_ld . append ( " -mfpu=neon " )
self . global_flags_ld . append ( " -mfloat-abi=softfp " )
self . global_flags_cc . append ( " -D__ARM_ARCH_7__ " )
self . global_flags_cc . append ( " -D__ARM_NEON__ " )
# the -mthumb must be set for all the android produc, some ot the not work coretly without this one ... (all android code is generated with this flags)
self . global_flags_cc . append ( " -mthumb " )
# -----------------------
# -- Common flags :
# -----------------------
self . global_flags_cc . append ( " -fpic " )
self . global_flags_cc . append ( " -ffunction-sections " )
self . global_flags_cc . append ( " -funwind-tables " )
self . global_flags_cc . append ( " -fstack-protector " )
self . global_flags_cc . append ( " -Wno-psabi " )
self . global_flags_cc . append ( " -mtune=xscale " )
2013-11-17 20:32:54 +01:00
self . global_flags_cc . append ( " -fexceptions " )
2013-11-20 21:26:31 +01:00
##self.global_flags_cc.append("-fno-exceptions")
2013-04-22 21:37:13 +02:00
self . global_flags_cc . append ( " -fomit-frame-pointer " )
self . global_flags_cc . append ( " -fno-strict-aliasing " )
2013-11-11 20:15:52 +01:00
self . global_flags_xx . append ( " -frtti " )
2013-04-22 21:37:13 +02:00
self . global_flags_xx . append ( " -Wa,--noexecstack " )
2013-04-23 21:48:36 +02:00
2013-04-22 21:37:13 +02:00
2013-12-23 22:22:24 +01:00
def check_right_package ( self , pkgProperties , value ) :
2013-04-23 21:48:36 +02:00
for val in pkgProperties [ " RIGHT " ] :
if value == val :
return True
return False
2013-04-22 21:37:13 +02:00
2013-12-23 22:22:24 +01:00
def get_staging_folder_data ( self , binaryName ) :
return self . get_staging_folder ( binaryName ) + self . folder_data
2013-07-13 22:15:07 +02:00
2013-12-23 22:22:24 +01:00
def make_package ( self , pkgName , pkgProperties , basePkgPath ) :
2013-04-23 21:48:36 +02:00
# http://alp.developpez.com/tutoriels/debian/creer-paquet/
debug . debug ( " ------------------------------------------------------------------------ " )
debug . info ( " Generate package ' " + pkgName + " ' " )
debug . debug ( " ------------------------------------------------------------------------ " )
2014-04-06 18:39:47 +02:00
pkgNameApplicationName = pkgName
if " debug " == self . buildMode :
pkgNameApplicationName + = " debug "
2013-04-23 21:48:36 +02:00
# FINAL_FOLDER_JAVA_PROJECT
2013-12-23 22:22:24 +01:00
self . folder_javaProject = self . get_staging_folder ( pkgName ) \
2013-04-23 21:48:36 +02:00
+ " /src/ " \
+ pkgProperties [ " COMPAGNY_TYPE " ] \
+ " / " + pkgProperties [ " COMPAGNY_NAME2 " ] \
2014-04-06 18:39:47 +02:00
+ " / " + pkgNameApplicationName + " / "
2013-04-23 21:48:36 +02:00
#FINAL_FILE_ABSTRACTION
2014-04-06 18:39:47 +02:00
self . file_finalAbstraction = self . folder_javaProject + " / " + pkgNameApplicationName + " .java "
compleatePackageName = pkgProperties [ " COMPAGNY_TYPE " ] + " . " + pkgProperties [ " COMPAGNY_NAME2 " ] + " . " + pkgNameApplicationName
if " ADMOD_ID " in pkgProperties :
pkgProperties [ " RIGHT " ] . append ( " INTERNET " )
pkgProperties [ " RIGHT " ] . append ( " ACCESS_NETWORK_STATE " )
2013-04-23 21:48:36 +02:00
2013-08-26 22:31:51 +02:00
2013-12-23 22:22:24 +01:00
debug . print_element ( " pkg " , " absractionFile " , " <== " , " dynamic file " )
2013-07-13 22:15:07 +02:00
# Create folder :
2013-12-23 22:22:24 +01:00
lutinTools . create_directory_of_file ( self . file_finalAbstraction )
2013-07-13 22:15:07 +02:00
# Create file :
tmpFile = open ( self . file_finalAbstraction , ' w ' )
2013-08-26 22:04:33 +02:00
if pkgProperties [ " ANDROID_APPL_TYPE " ] == " APPL " :
tmpFile . write ( " /** \n " )
tmpFile . write ( " * @author Edouard DUPIN, Kevin BILLONNEAU \n " )
tmpFile . write ( " * @copyright 2011, Edouard DUPIN, all right reserved \n " )
2014-08-09 23:55:31 +02:00
tmpFile . write ( " * @license APACHE v2.0 (see license file) \n " )
2013-08-26 22:04:33 +02:00
tmpFile . write ( " * @note This file is autogenerate ==> see documantation to generate your own \n " )
tmpFile . write ( " */ \n " )
2013-08-26 22:31:51 +02:00
tmpFile . write ( " package " + compleatePackageName + " ; \n " )
2013-08-26 22:04:33 +02:00
tmpFile . write ( " import org.ewol.EwolActivity; \n " )
2014-04-06 18:39:47 +02:00
if " ADMOD_ID " in pkgProperties :
tmpFile . write ( " import com.google.android.gms.ads.AdRequest; \n " )
tmpFile . write ( " import com.google.android.gms.ads.AdSize; \n " )
tmpFile . write ( " import com.google.android.gms.ads.AdView; \n " )
tmpFile . write ( " import android.widget.LinearLayout; \n " )
tmpFile . write ( " import android.widget.Button; \n " )
tmpFile . write ( " public class " + pkgNameApplicationName + " extends EwolActivity { \n " )
if " ADMOD_ID " in pkgProperties :
tmpFile . write ( " /** The view to show the ad. */ \n " )
tmpFile . write ( " private AdView adView; \n " )
tmpFile . write ( " private LinearLayout mLayout = null; \n " )
2013-08-26 22:04:33 +02:00
tmpFile . write ( " public void onCreate(android.os.Bundle savedInstanceState) { \n " )
tmpFile . write ( " super.onCreate(savedInstanceState); \n " )
2014-04-06 18:39:47 +02:00
tmpFile . write ( " initApkPath( \" " + pkgProperties [ " COMPAGNY_TYPE " ] + " \" , \" " + pkgProperties [ " COMPAGNY_NAME2 " ] + " \" , \" " + pkgNameApplicationName + " \" ); \n " )
if " ADMOD_ID " in pkgProperties :
tmpFile . write ( " mLayout = new LinearLayout(this); \n " )
tmpFile . write ( " mLayout.setOrientation(android.widget.LinearLayout.VERTICAL); \n " )
2014-06-03 23:34:15 +02:00
tmpFile . write ( " LinearLayout.LayoutParams paramsWindows = new LinearLayout.LayoutParams( \n " )
tmpFile . write ( " LinearLayout.LayoutParams.FILL_PARENT, \n " )
tmpFile . write ( " LinearLayout.LayoutParams.FILL_PARENT); \n " )
2014-04-06 18:39:47 +02:00
tmpFile . write ( " \n " )
2014-06-03 23:34:15 +02:00
tmpFile . write ( " setContentView(mLayout, paramsWindows); \n " )
tmpFile . write ( " \n " )
tmpFile . write ( " LinearLayout.LayoutParams paramsAdds = new LinearLayout.LayoutParams( \n " )
tmpFile . write ( " LinearLayout.LayoutParams.FILL_PARENT, \n " )
2014-04-06 18:39:47 +02:00
tmpFile . write ( " LinearLayout.LayoutParams.WRAP_CONTENT); \n " )
2014-06-03 23:34:15 +02:00
tmpFile . write ( " paramsAdds.weight = 0; \n " )
tmpFile . write ( " \n " )
tmpFile . write ( " LinearLayout.LayoutParams paramsGLView = new LinearLayout.LayoutParams( \n " )
tmpFile . write ( " LinearLayout.LayoutParams.FILL_PARENT, \n " )
tmpFile . write ( " LinearLayout.LayoutParams.FILL_PARENT); \n " )
tmpFile . write ( " paramsGLView.weight = 1; \n " )
tmpFile . write ( " paramsGLView.height = 0; \n " )
2014-04-06 18:39:47 +02:00
tmpFile . write ( " \n " )
2014-06-03 23:34:15 +02:00
tmpFile . write ( " mLayout.setGravity(android.view.Gravity.TOP); \n " )
2014-04-06 18:39:47 +02:00
tmpFile . write ( " \n " )
tmpFile . write ( " // Create an adds. \n " )
tmpFile . write ( " adView = new AdView(this); \n " )
tmpFile . write ( " adView.setAdSize(AdSize.SMART_BANNER); \n " )
tmpFile . write ( " adView.setAdUnitId( \" " + pkgProperties [ " ADMOD_ID " ] + " \" ); \n " )
tmpFile . write ( " \n " )
tmpFile . write ( " // Create an ad request. Check logcat output for the hashed device ID to get test ads on a physical device. \n " )
tmpFile . write ( " AdRequest adRequest = new AdRequest.Builder() \n " )
tmpFile . write ( " .addTestDevice(AdRequest.DEVICE_ID_EMULATOR) \n " )
tmpFile . write ( " .build(); \n " )
tmpFile . write ( " \n " )
2014-06-03 23:34:15 +02:00
tmpFile . write ( " // Add the AdView to the view hierarchy. The view will have no size until the ad is loaded. \n " )
if " ADMOD_POSITION " in pkgProperties . keys ( ) \
and pkgProperties [ " ADMOD_POSITION " ] == " top " :
tmpFile . write ( " mLayout.addView(adView, paramsAdds); \n " )
tmpFile . write ( " mLayout.addView(mGLView, paramsGLView); \n " )
else :
tmpFile . write ( " mLayout.addView(mGLView, paramsGLView); \n " )
tmpFile . write ( " mLayout.addView(adView, paramsAdds); \n " )
tmpFile . write ( " \n " )
2014-04-06 18:39:47 +02:00
tmpFile . write ( " // Start loading the ad in the background. \n " )
tmpFile . write ( " adView.loadAd(adRequest); \n " )
2013-08-26 22:04:33 +02:00
tmpFile . write ( " } \n " )
2014-04-06 18:39:47 +02:00
if " ADMOD_ID " in pkgProperties :
tmpFile . write ( " @Override protected void onResume() { \n " )
tmpFile . write ( " super.onResume(); \n " )
tmpFile . write ( " if (adView != null) { \n " )
tmpFile . write ( " adView.resume(); \n " )
tmpFile . write ( " } \n " )
tmpFile . write ( " } \n " )
tmpFile . write ( " @Override protected void onPause() { \n " )
tmpFile . write ( " if (adView != null) { \n " )
tmpFile . write ( " adView.pause(); \n " )
tmpFile . write ( " } \n " )
tmpFile . write ( " super.onPause(); \n " )
tmpFile . write ( " } \n " )
tmpFile . write ( " @Override protected void onDestroy() { \n " )
tmpFile . write ( " // Destroy the AdView. \n " )
tmpFile . write ( " if (adView != null) { \n " )
tmpFile . write ( " adView.destroy(); \n " )
tmpFile . write ( " } \n " )
tmpFile . write ( " super.onDestroy(); \n " )
tmpFile . write ( " } \n " )
2013-08-26 22:04:33 +02:00
tmpFile . write ( " } \n " )
else :
# wallpaper mode ...
tmpFile . write ( " /** \n " )
tmpFile . write ( " * @author Edouard DUPIN, Kevin BILLONNEAU \n " )
tmpFile . write ( " * @copyright 2011, Edouard DUPIN, all right reserved \n " )
2014-08-09 23:55:31 +02:00
tmpFile . write ( " * @license APACHE v2.0 (see license file) \n " )
2013-08-26 22:04:33 +02:00
tmpFile . write ( " * @note This file is autogenerate ==> see documantation to generate your own \n " )
tmpFile . write ( " */ \n " )
2013-08-26 22:31:51 +02:00
tmpFile . write ( " package " + compleatePackageName + " ; \n " )
2013-08-26 22:04:33 +02:00
tmpFile . write ( " import org.ewol.EwolWallpaper; \n " )
2014-04-06 18:39:47 +02:00
tmpFile . write ( " public class " + pkgNameApplicationName + " extends EwolWallpaper { \n " )
tmpFile . write ( " public static final String SHARED_PREFS_NAME = \" " + pkgNameApplicationName + " settings \" ; \n " )
2013-08-26 22:04:33 +02:00
tmpFile . write ( " public Engine onCreateEngine() { \n " )
tmpFile . write ( " Engine tmpEngine = super.onCreateEngine(); \n " )
2014-04-06 18:39:47 +02:00
tmpFile . write ( " initApkPath( \" " + pkgProperties [ " COMPAGNY_TYPE " ] + " \" , \" " + pkgProperties [ " COMPAGNY_NAME2 " ] + " \" , \" " + pkgNameApplicationName + " \" ); \n " )
2013-08-26 22:04:33 +02:00
tmpFile . write ( " return tmpEngine; \n " )
tmpFile . write ( " } \n " )
tmpFile . write ( " } \n " )
2013-07-13 22:15:07 +02:00
tmpFile . flush ( )
tmpFile . close ( )
2013-04-23 21:48:36 +02:00
2014-03-20 10:27:28 +01:00
lutinTools . create_directory_of_file ( self . get_staging_folder ( pkgName ) + " /res/drawable/icon.png " ) ;
2014-01-05 23:01:30 +01:00
if " ICON " in pkgProperties . keys ( ) \
and pkgProperties [ " ICON " ] != " " :
2014-05-01 20:58:48 +02:00
lutinImage . resize ( pkgProperties [ " ICON " ] , self . get_staging_folder ( pkgName ) + " /res/drawable/icon.png " , 256 , 256 )
2014-03-20 10:27:28 +01:00
else :
# to be sure that we have all time a resource ...
tmpFile = open ( self . get_staging_folder ( pkgName ) + " /res/drawable/plop.txt " , ' w ' )
tmpFile . write ( ' plop \n ' )
tmpFile . flush ( )
tmpFile . close ( )
2013-08-25 23:28:25 +02:00
2013-08-26 22:04:33 +02:00
if pkgProperties [ " ANDROID_MANIFEST " ] != " " :
2013-12-23 22:22:24 +01:00
debug . print_element ( " pkg " , " AndroidManifest.xml " , " <== " , pkgProperties [ " ANDROID_MANIFEST " ] )
2014-06-18 11:52:01 +02:00
lutinTools . copy_file ( pkgProperties [ " ANDROID_MANIFEST " ] , self . get_staging_folder ( pkgName ) + " /AndroidManifest.xml " , force = True )
2013-04-23 21:48:36 +02:00
else :
2014-04-13 16:53:45 +02:00
if " VERSION_CODE " not in pkgProperties :
pkgProperties [ " VERSION_CODE " ] = " 1 "
2013-12-23 22:22:24 +01:00
debug . print_element ( " pkg " , " AndroidManifest.xml " , " <== " , " package configurations " )
tmpFile = open ( self . get_staging_folder ( pkgName ) + " /AndroidManifest.xml " , ' w ' )
2014-01-03 21:07:19 +01:00
tmpFile . write ( ' <?xml version= " 1.0 " encoding= " utf-8 " ?> \n ' )
tmpFile . write ( ' <!-- Manifest is autoGenerated with Ewol ... do not patch it--> \n ' )
tmpFile . write ( ' <manifest xmlns:android= " http://schemas.android.com/apk/res/android " \n ' )
tmpFile . write ( ' package= " ' + compleatePackageName + ' " \n ' )
2014-04-13 16:53:45 +02:00
tmpFile . write ( ' android:versionCode= " ' + pkgProperties [ " VERSION_CODE " ] + ' " \n ' )
2014-01-03 21:07:19 +01:00
tmpFile . write ( ' android:versionName= " ' + pkgProperties [ " VERSION " ] + ' " > \n ' )
tmpFile . write ( ' <uses-feature android:glEsVersion= " 0x00020000 " android:required= " true " /> \n ' )
2014-04-06 18:39:47 +02:00
tmpFile . write ( ' <uses-sdk android:minSdkVersion= " ' + str ( self . boardId ) + ' " \n ' )
2014-01-03 21:07:19 +01:00
tmpFile . write ( ' android:targetSdkVersion= " ' + str ( self . boardId ) + ' " /> \n ' )
2013-08-26 22:04:33 +02:00
if pkgProperties [ " ANDROID_APPL_TYPE " ] == " APPL " :
2014-04-06 18:39:47 +02:00
tmpFile . write ( ' <application android:label= " ' + pkgNameApplicationName + ' " \n ' )
2014-03-20 10:27:28 +01:00
if " ICON " in pkgProperties . keys ( ) :
tmpFile . write ( ' android:icon= " @drawable/icon " \n ' )
2014-01-03 21:07:19 +01:00
if " debug " == self . buildMode :
tmpFile . write ( ' android:debuggable= " true " \n ' )
tmpFile . write ( ' > \n ' )
2014-04-06 18:39:47 +02:00
if " ADMOD_ID " in pkgProperties :
tmpFile . write ( ' <meta-data android:name= " com.google.android.gms.version " \n ' )
tmpFile . write ( ' android:value= " @integer/google_play_services_version " /> \n ' )
tmpFile . write ( ' <activity android:name= " . ' + pkgNameApplicationName + ' " \n ' )
2014-01-03 21:07:19 +01:00
tmpFile . write ( ' android:label= " ' + pkgProperties [ ' NAME ' ] )
2013-08-26 22:04:33 +02:00
if " debug " == self . buildMode :
tmpFile . write ( " -debug " )
2014-01-03 21:07:19 +01:00
tmpFile . write ( ' " \n ' )
2014-03-20 10:27:28 +01:00
if " ICON " in pkgProperties . keys ( ) :
tmpFile . write ( ' android:icon= " @drawable/icon " \n ' )
2014-01-03 21:07:19 +01:00
tmpFile . write ( ' android:hardwareAccelerated= " true " \n ' )
tmpFile . write ( ' android:configChanges= " keyboard|keyboardHidden|orientation|screenSize " > \n ' )
tmpFile . write ( ' <intent-filter> \n ' )
tmpFile . write ( ' <action android:name= " android.intent.action.MAIN " /> \n ' )
tmpFile . write ( ' <category android:name= " android.intent.category.LAUNCHER " /> \n ' )
tmpFile . write ( ' </intent-filter> \n ' )
tmpFile . write ( ' </activity> \n ' )
2014-04-06 18:39:47 +02:00
if " ADMOD_ID " in pkgProperties :
tmpFile . write ( ' <activity android:name= " com.google.android.gms.ads.AdActivity " \n ' )
tmpFile . write ( ' android:configChanges= " keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize " /> \n ' )
2014-03-04 21:46:49 +01:00
tmpFile . write ( ' </application> \n ' )
2013-08-25 23:28:25 +02:00
else :
2014-04-06 18:39:47 +02:00
tmpFile . write ( ' <application android:label= " ' + pkgNameApplicationName + ' " \n ' )
2014-01-03 21:07:19 +01:00
tmpFile . write ( ' android:permission= " android.permission.BIND_WALLPAPER " \n ' )
2014-03-20 10:27:28 +01:00
if " ICON " in pkgProperties . keys ( ) :
tmpFile . write ( ' android:icon= " @drawable/icon " \n ' )
tmpFile . write ( ' > \n ' )
2014-04-06 18:39:47 +02:00
tmpFile . write ( ' <service android:name= " . ' + pkgNameApplicationName + ' " \n ' )
2014-01-03 21:07:19 +01:00
tmpFile . write ( ' android:label= " ' + pkgProperties [ ' NAME ' ] )
2013-08-26 22:04:33 +02:00
if " debug " == self . buildMode :
tmpFile . write ( " -debug " )
2014-01-03 21:07:19 +01:00
tmpFile . write ( ' " \n ' )
2014-03-20 10:27:28 +01:00
if " ICON " in pkgProperties . keys ( ) :
tmpFile . write ( ' android:icon= " @drawable/icon " \n ' )
tmpFile . write ( ' > \n ' )
2014-01-03 21:07:19 +01:00
tmpFile . write ( ' <intent-filter> \n ' )
tmpFile . write ( ' <action android:name= " android.service.wallpaper.WallpaperService " /> \n ' )
tmpFile . write ( ' </intent-filter> \n ' )
tmpFile . write ( ' <meta-data android:name= " android.service.wallpaper " \n ' )
2014-04-06 18:39:47 +02:00
tmpFile . write ( ' android:resource= " @xml/ ' + pkgNameApplicationName + ' _resource " /> \n ' )
2014-01-03 21:07:19 +01:00
tmpFile . write ( ' </service> \n ' )
2013-08-26 22:31:51 +02:00
if len ( pkgProperties [ " ANDROID_WALLPAPER_PROPERTIES " ] ) != 0 :
2014-01-03 21:07:19 +01:00
tmpFile . write ( ' <activity android:label= " Setting " \n ' )
2014-04-06 18:39:47 +02:00
tmpFile . write ( ' android:name= " . ' + pkgNameApplicationName + ' Settings " \n ' )
2014-01-03 21:07:19 +01:00
tmpFile . write ( ' android:theme= " @android:style/Theme.Light.WallpaperSettings " \n ' )
tmpFile . write ( ' android:exported= " true " \n ' )
2014-03-20 10:27:28 +01:00
if " ICON " in pkgProperties . keys ( ) :
tmpFile . write ( ' android:icon= " @drawable/icon " \n ' )
tmpFile . write ( ' > \n ' )
2014-01-03 21:07:19 +01:00
tmpFile . write ( ' </activity> \n ' )
tmpFile . write ( ' </application> \n ' )
2013-08-26 22:04:33 +02:00
# write package autorisations :
2013-12-23 22:22:24 +01:00
if True == self . check_right_package ( pkgProperties , " WRITE_EXTERNAL_STORAGE " ) :
2014-03-04 21:46:49 +01:00
tmpFile . write ( ' <permission android:name= " android.permission.WRITE_EXTERNAL_STORAGE " /> \n ' )
2014-01-03 21:07:19 +01:00
tmpFile . write ( ' <uses-permission android:name= " android.permission.WRITE_EXTERNAL_STORAGE " /> \n ' )
2013-12-23 22:22:24 +01:00
if True == self . check_right_package ( pkgProperties , " CAMERA " ) :
2014-03-04 21:46:49 +01:00
tmpFile . write ( ' <permission android:name= " android.permission.CAMERA " /> \n ' )
2014-01-03 21:07:19 +01:00
tmpFile . write ( ' <uses-permission android:name= " android.permission.CAMERA " /> \n ' )
2013-12-23 22:22:24 +01:00
if True == self . check_right_package ( pkgProperties , " INTERNET " ) :
2014-03-04 21:46:49 +01:00
tmpFile . write ( ' <permission android:name= " android.permission.INTERNET " /> \n ' )
2014-01-03 21:07:19 +01:00
tmpFile . write ( ' <uses-permission android:name= " android.permission.INTERNET " /> \n ' )
2014-04-06 18:39:47 +02:00
if True == self . check_right_package ( pkgProperties , " ACCESS_NETWORK_STATE " ) :
tmpFile . write ( ' <permission android:name= " android.permission.ACCESS_NETWORK_STATE " /> \n ' )
tmpFile . write ( ' <uses-permission android:name= " android.permission.ACCESS_NETWORK_STATE " /> \n ' )
2013-12-23 22:22:24 +01:00
if True == self . check_right_package ( pkgProperties , " MODIFY_AUDIO_SETTINGS " ) :
2014-03-04 21:46:49 +01:00
tmpFile . write ( ' <permission android:name= " android.permission.MODIFY_AUDIO_SETTINGS " /> \n ' )
2014-01-03 21:07:19 +01:00
tmpFile . write ( ' <uses-permission android:name= " android.permission.MODIFY_AUDIO_SETTINGS " /> \n ' )
2013-12-23 22:22:24 +01:00
if True == self . check_right_package ( pkgProperties , " READ_CALENDAR " ) :
2014-03-04 21:46:49 +01:00
tmpFile . write ( ' <permission android:name= " android.permission.READ_CALENDAR " /> \n ' )
2014-01-03 21:07:19 +01:00
tmpFile . write ( ' <uses-permission android:name= " android.permission.READ_CALENDAR " /> \n ' )
2013-12-23 22:22:24 +01:00
if True == self . check_right_package ( pkgProperties , " READ_CONTACTS " ) :
2014-03-04 21:46:49 +01:00
tmpFile . write ( ' <permission android:name= " android.permission.READ_CONTACTS " /> \n ' )
2014-01-03 21:07:19 +01:00
tmpFile . write ( ' <uses-permission android:name= " android.permission.READ_CONTACTS " /> \n ' )
2013-12-23 22:22:24 +01:00
if True == self . check_right_package ( pkgProperties , " READ_FRAME_BUFFER " ) :
2014-03-04 21:46:49 +01:00
tmpFile . write ( ' <permission android:name= " android.permission.READ_FRAME_BUFFER " /> \n ' )
2014-01-03 21:07:19 +01:00
tmpFile . write ( ' <uses-permission android:name= " android.permission.READ_FRAME_BUFFER " /> \n ' )
2013-12-23 22:22:24 +01:00
if True == self . check_right_package ( pkgProperties , " READ_PROFILE " ) :
2014-03-04 21:46:49 +01:00
tmpFile . write ( ' <permission android:name= " android.permission.READ_PROFILE " /> \n ' )
2014-01-03 21:07:19 +01:00
tmpFile . write ( ' <uses-permission android:name= " android.permission.READ_PROFILE " /> \n ' )
2013-12-23 22:22:24 +01:00
if True == self . check_right_package ( pkgProperties , " RECORD_AUDIO " ) :
2014-03-04 21:46:49 +01:00
tmpFile . write ( ' <permission android:name= " android.permission.RECORD_AUDIO " /> \n ' )
2014-01-03 21:07:19 +01:00
tmpFile . write ( ' <uses-permission android:name= " android.permission.RECORD_AUDIO " /> \n ' )
2013-12-23 22:22:24 +01:00
if True == self . check_right_package ( pkgProperties , " SET_ORIENTATION " ) :
2014-03-04 21:46:49 +01:00
tmpFile . write ( ' <permission android:name= " android.permission.SET_ORIENTATION " /> \n ' )
2014-01-03 21:07:19 +01:00
tmpFile . write ( ' <uses-permission android:name= " android.permission.SET_ORIENTATION " /> \n ' )
2013-12-23 22:22:24 +01:00
if True == self . check_right_package ( pkgProperties , " VIBRATE " ) :
2014-03-04 21:46:49 +01:00
tmpFile . write ( ' <permission android:name= " android.permission.VIBRATE " /> \n ' )
2014-01-03 21:07:19 +01:00
tmpFile . write ( ' <uses-permission android:name= " android.permission.VIBRATE " /> \n ' )
2013-12-23 22:22:24 +01:00
if True == self . check_right_package ( pkgProperties , " ACCESS_COARSE_LOCATION " ) :
2014-03-04 21:46:49 +01:00
tmpFile . write ( ' <permission android:name= " android.permission.ACCESS_COARSE_LOCATION " /> \n ' )
2014-01-03 21:07:19 +01:00
tmpFile . write ( ' <uses-permission android:name= " android.permission.ACCESS_COARSE_LOCATION " /> \n ' )
2013-12-23 22:22:24 +01:00
if True == self . check_right_package ( pkgProperties , " ACCESS_FINE_LOCATION " ) :
2014-03-04 21:46:49 +01:00
tmpFile . write ( ' <permission android:name= " android.permission.ACCESS_FINE_LOCATION " /> \n ' )
2014-01-03 21:07:19 +01:00
tmpFile . write ( ' <uses-permission android:name= " android.permission.ACCESS_FINE_LOCATION " /> \n ' )
tmpFile . write ( ' </manifest> \n \n ' )
2013-08-25 23:28:25 +02:00
tmpFile . flush ( )
tmpFile . close ( )
2013-08-26 22:31:51 +02:00
# end generating android manifest
if pkgProperties [ " ANDROID_APPL_TYPE " ] != " APPL " :
#create the Wallpaper sub files : (main element for the application
2014-04-06 18:39:47 +02:00
debug . print_element ( " pkg " , pkgNameApplicationName + " _resource.xml " , " <== " , " package configurations " )
lutinTools . create_directory_of_file ( self . get_staging_folder ( pkgName ) + " /res/xml/ " + pkgNameApplicationName + " _resource.xml " )
tmpFile = open ( self . get_staging_folder ( pkgName ) + " /res/xml/ " + pkgNameApplicationName + " _resource.xml " , ' w ' )
2013-08-26 22:31:51 +02:00
tmpFile . write ( " <?xml version= \" 1.0 \" encoding= \" utf-8 \" ?> \n " )
tmpFile . write ( " <wallpaper xmlns:android= \" http://schemas.android.com/apk/res/android \" \n " )
if len ( pkgProperties [ " ANDROID_WALLPAPER_PROPERTIES " ] ) != 0 :
2014-04-06 18:39:47 +02:00
tmpFile . write ( " android:settingsActivity= \" " + compleatePackageName + " . " + pkgNameApplicationName + " Settings \" \n " )
2014-03-20 10:27:28 +01:00
if " ICON " in pkgProperties . keys ( ) :
tmpFile . write ( " android:thumbnail= \" @drawable/icon \" \n " )
tmpFile . write ( " /> \n " )
2013-08-26 22:31:51 +02:00
tmpFile . flush ( )
tmpFile . close ( )
# create wallpaper setting if needed (class and config file)
if len ( pkgProperties [ " ANDROID_WALLPAPER_PROPERTIES " ] ) != 0 :
2014-04-06 18:39:47 +02:00
lutinTools . create_directory_of_file ( self . folder_javaProject + pkgNameApplicationName + " Settings.java " )
debug . print_element ( " pkg " , self . folder_javaProject + pkgNameApplicationName + " Settings.java " , " <== " , " package configurations " )
tmpFile = open ( self . folder_javaProject + pkgNameApplicationName + " Settings.java " , ' w ' ) ;
2013-08-26 22:31:51 +02:00
tmpFile . write ( " package " + compleatePackageName + " ; \n " )
tmpFile . write ( " \n " )
tmpFile . write ( " import " + compleatePackageName + " .R; \n " )
tmpFile . write ( " \n " )
tmpFile . write ( " import android.content.SharedPreferences; \n " )
tmpFile . write ( " import android.os.Bundle; \n " )
tmpFile . write ( " import android.preference.PreferenceActivity; \n " )
tmpFile . write ( " \n " )
2014-04-06 18:39:47 +02:00
tmpFile . write ( " public class " + pkgNameApplicationName + " Settings extends PreferenceActivity implements SharedPreferences.OnSharedPreferenceChangeListener \n " )
2013-08-26 22:31:51 +02:00
tmpFile . write ( " { \n " )
tmpFile . write ( " @Override protected void onCreate(Bundle icicle) { \n " )
tmpFile . write ( " super.onCreate(icicle); \n " )
2014-04-06 18:39:47 +02:00
tmpFile . write ( " getPreferenceManager().setSharedPreferencesName( " + pkgNameApplicationName + " .SHARED_PREFS_NAME); \n " )
tmpFile . write ( " addPreferencesFromResource(R.xml. " + pkgNameApplicationName + " _settings); \n " )
2013-08-26 22:31:51 +02:00
tmpFile . write ( " getPreferenceManager().getSharedPreferences().registerOnSharedPreferenceChangeListener(this); \n " )
tmpFile . write ( " } \n " )
tmpFile . write ( " @Override protected void onResume() { \n " )
tmpFile . write ( " super.onResume(); \n " )
tmpFile . write ( " } \n " )
tmpFile . write ( " @Override protected void onDestroy() { \n " )
tmpFile . write ( " getPreferenceManager().getSharedPreferences().unregisterOnSharedPreferenceChangeListener(this); \n " )
tmpFile . write ( " super.onDestroy(); \n " )
tmpFile . write ( " } \n " )
tmpFile . write ( " public void onSharedPreferenceChanged(SharedPreferences sharedPreferences,String key) { } \n " )
tmpFile . write ( " } \n " )
tmpFile . flush ( )
tmpFile . close ( )
2014-04-06 18:39:47 +02:00
debug . print_element ( " pkg " , self . get_staging_folder ( pkgName ) + " /res/xml/ " + pkgNameApplicationName + " _settings.xml " , " <== " , " package configurations " )
lutinTools . create_directory_of_file ( self . get_staging_folder ( pkgName ) + " /res/xml/ " + pkgNameApplicationName + " _settings.xml " )
tmpFile = open ( self . get_staging_folder ( pkgName ) + " /res/xml/ " + pkgNameApplicationName + " _settings.xml " , ' w ' ) ;
2013-08-26 22:31:51 +02:00
tmpFile . write ( " <?xml version= \" 1.0 \" encoding= \" utf-8 \" ?> \n " )
tmpFile . write ( " <PreferenceScreen xmlns:android= \" http://schemas.android.com/apk/res/android \" \n " )
tmpFile . write ( " android:title= \" Settings \" \n " )
2014-04-06 18:39:47 +02:00
tmpFile . write ( " android:key= \" " + pkgNameApplicationName + " _settings \" > \n " )
2013-08-26 22:31:51 +02:00
WALL_haveArray = False
for WALL_type , WALL_key , WALL_title , WALL_summary , WALL_other in pkgProperties [ " ANDROID_WALLPAPER_PROPERTIES " ] :
debug . info ( " find : ' " + WALL_type + " ' " ) ;
if WALL_type == " list " :
debug . info ( " create : LIST " ) ;
2014-04-06 18:39:47 +02:00
tmpFile . write ( " <ListPreference android:key= \" " + pkgNameApplicationName + " _ " + WALL_key + " \" \n " )
2013-08-26 22:31:51 +02:00
tmpFile . write ( " android:title= \" " + WALL_title + " \" \n " )
tmpFile . write ( " android:summary= \" " + WALL_summary + " \" \n " )
2014-04-06 18:39:47 +02:00
tmpFile . write ( " android:entries= \" @array/ " + pkgNameApplicationName + " _ " + WALL_key + " _names \" \n " )
tmpFile . write ( " android:entryValues= \" @array/ " + pkgNameApplicationName + " _ " + WALL_key + " _prefix \" /> \n " )
2013-08-26 22:31:51 +02:00
WALL_haveArray = True
elif WALL_type == " bool " :
debug . info ( " create : CHECKBOX " ) ;
2014-04-06 18:39:47 +02:00
tmpFile . write ( " <CheckBoxPreference android:key= \" " + pkgNameApplicationName + " _ " + WALL_key + " \" \n " )
2013-08-26 22:31:51 +02:00
tmpFile . write ( " android:title= \" " + WALL_title + " \" \n " )
tmpFile . write ( " android:summary= \" " + WALL_summary + " \" \n " )
tmpFile . write ( " android:summaryOn= \" " + WALL_other [ 0 ] + " \" \n " )
tmpFile . write ( " android:summaryOff= \" " + WALL_other [ 1 ] + " \" /> \n " )
tmpFile . write ( " </PreferenceScreen> \n " )
tmpFile . flush ( )
tmpFile . close ( )
if WALL_haveArray == True :
for WALL_type , WALL_key , WALL_title , WALL_summary , WALL_other in pkgProperties [ " ANDROID_WALLPAPER_PROPERTIES " ] :
if WALL_type == " list " :
2013-12-23 22:22:24 +01:00
debug . print_element ( " pkg " , self . get_staging_folder ( pkgName ) + " /res/values/ " + WALL_key + " .xml " , " <== " , " package configurations " )
lutinTools . create_directory_of_file ( self . get_staging_folder ( pkgName ) + " /res/values/ " + WALL_key + " .xml " )
tmpFile = open ( self . get_staging_folder ( pkgName ) + " /res/values/ " + WALL_key + " .xml " , ' w ' ) ;
2013-08-26 22:31:51 +02:00
tmpFile . write ( " <?xml version= \" 1.0 \" encoding= \" utf-8 \" ?> \n " )
tmpFile . write ( " <resources xmlns:xliff= \" urn:oasis:names:tc:xliff:document:1.2 \" > \n " )
2014-04-06 18:39:47 +02:00
tmpFile . write ( " <string-array name= \" " + pkgNameApplicationName + " _ " + WALL_key + " _names \" > \n " )
2013-08-26 22:31:51 +02:00
for WALL_subKey , WALL_display in WALL_other :
tmpFile . write ( " <item> " + WALL_display + " </item> \n " )
tmpFile . write ( " </string-array> \n " )
2014-04-06 18:39:47 +02:00
tmpFile . write ( " <string-array name= \" " + pkgNameApplicationName + " _ " + WALL_key + " _prefix \" > \n " )
2013-08-26 22:31:51 +02:00
for WALL_subKey , WALL_display in WALL_other :
tmpFile . write ( " <item> " + WALL_subKey + " </item> \n " )
tmpFile . write ( " </string-array> \n " )
tmpFile . write ( " </resources> \n " )
tmpFile . flush ( )
tmpFile . close ( )
2013-08-25 23:28:25 +02:00
2013-08-26 22:31:51 +02:00
#add properties on wallpaper :
2013-12-23 22:22:24 +01:00
# myModule.pkg_add("ANDROID_WALLPAPER_PROPERTIES", ["list", key, title, summary, [["key","value display"],["key2","value display 2"]])
# myModule.pkg_add("ANDROID_WALLPAPER_PROPERTIES", ["list", "testpattern", "Select test pattern", "Choose which test pattern to display", [["key","value display"],["key2","value display 2"]]])
# myModule.pkg_add("ANDROID_WALLPAPER_PROPERTIES", ["bool", key, title, summary, ["enable string", "disable String"])
# myModule.pkg_add("ANDROID_WALLPAPER_PROPERTIES", ["bool", "movement", "Motion", "Apply movement to test pattern", ["Moving test pattern", "Still test pattern"]
2013-08-25 23:28:25 +02:00
#copy needed resources :
for res_source , res_dest in pkgProperties [ " ANDROID_RESOURCES " ] :
if res_source == " " :
continue
2014-06-18 11:52:01 +02:00
lutinTools . copy_file ( res_source , self . get_staging_folder ( pkgName ) + " /res/ " + res_dest + " / " + os . path . basename ( res_source ) , force = True )
2013-08-25 23:28:25 +02:00
2013-04-23 21:48:36 +02:00
# Doc :
# http://asantoso.wordpress.com/2009/09/15/how-to-build-android-application-package-apk-from-the-command-line-using-the-sdk-tools-continuously-integrated-using-cruisecontrol/
2013-12-23 22:22:24 +01:00
debug . print_element ( " pkg " , " R.java " , " <== " , " Resources files " )
lutinTools . create_directory_of_file ( self . get_staging_folder ( pkgName ) + " /src/noFile " )
2014-04-06 18:39:47 +02:00
androidToolPath = self . folder_sdk + " /build-tools/19.0.3/ "
adModResouceFolder = " "
if " ADMOD_ID " in pkgProperties :
adModResouceFolder = " -S " + self . folder_sdk + " /extras/google/google_play_services/libproject/google-play-services_lib/res/ "
2013-11-06 21:13:30 +01:00
cmdLine = androidToolPath + " aapt p -f " \
2013-12-23 22:22:24 +01:00
+ " -M " + self . get_staging_folder ( pkgName ) + " /AndroidManifest.xml " \
+ " -F " + self . get_staging_folder ( pkgName ) + " /resources.res " \
2013-04-23 21:48:36 +02:00
+ " -I " + self . folder_sdk + " /platforms/android- " + str ( self . boardId ) + " /android.jar " \
2013-12-23 22:22:24 +01:00
+ " -S " + self . get_staging_folder ( pkgName ) + " /res/ " \
2014-04-06 18:39:47 +02:00
+ adModResouceFolder \
+ " -J " + self . get_staging_folder ( pkgName ) + " /src/ "
2013-12-23 22:22:24 +01:00
lutinMultiprocess . run_command ( cmdLine )
2013-04-23 21:48:36 +02:00
#aapt package -f -M ${manifest.file} -F ${packaged.resource.file} -I ${path.to.android-jar.library}
# -S ${android-resource-directory} [-m -J ${folder.to.output.the.R.java}]
2013-12-23 22:22:24 +01:00
lutinTools . create_directory_of_file ( self . get_staging_folder ( pkgName ) + " /build/classes/noFile " )
debug . print_element ( " pkg " , " *.class " , " <== " , " *.java " )
2013-04-23 21:48:36 +02:00
# more information with : -Xlint
2013-07-03 21:32:04 +02:00
# + self.file_finalAbstraction + " "\ # this generate ex: out/Android/debug/staging/tethys/src/com/edouarddupin/tethys/edn.java
2013-08-25 23:28:25 +02:00
#generate android java files:
filesString = " "
for element in pkgProperties [ " ANDROID_JAVA_FILES " ] :
if element == " DEFAULT " :
filesString + = self . folder_ewol + " /sources/android/src/org/ewol/EwolAudioTask.java "
filesString + = self . folder_ewol + " /sources/android/src/org/ewol/EwolCallback.java "
filesString + = self . folder_ewol + " /sources/android/src/org/ewol/EwolConstants.java "
filesString + = self . folder_ewol + " /sources/android/src/org/ewol/Ewol.java "
filesString + = self . folder_ewol + " /sources/android/src/org/ewol/EwolRendererGL.java "
filesString + = self . folder_ewol + " /sources/android/src/org/ewol/EwolSurfaceViewGL.java "
filesString + = self . folder_ewol + " /sources/android/src/org/ewol/EwolActivity.java "
2013-08-26 22:04:33 +02:00
filesString + = self . folder_ewol + " /sources/android/src/org/ewol/EwolWallpaper.java "
2013-08-25 23:28:25 +02:00
else :
filesString + = element + " "
2014-04-06 18:39:47 +02:00
if " ADMOD_ID " in pkgProperties :
filesString + = self . folder_sdk + " /extras/google/google_play_services/libproject/google-play-services_lib/src/android/UnusedStub.java "
2013-08-26 22:31:51 +02:00
if len ( pkgProperties [ " ANDROID_WALLPAPER_PROPERTIES " ] ) != 0 :
2014-04-06 18:39:47 +02:00
filesString + = self . folder_javaProject + pkgNameApplicationName + " Settings.java "
adModJarFile = " "
if " ADMOD_ID " in pkgProperties :
adModJarFile = " : " + self . folder_sdk + " /extras/google/google_play_services/libproject/google-play-services_lib/libs/google-play-services.jar "
2013-08-25 23:28:25 +02:00
2013-04-23 21:48:36 +02:00
cmdLine = " javac " \
2013-12-23 22:22:24 +01:00
+ " -d " + self . get_staging_folder ( pkgName ) + " /build/classes " \
2014-04-06 18:39:47 +02:00
+ " -classpath " + self . folder_sdk + " /platforms/android- " + str ( self . boardId ) + " /android.jar " \
+ adModJarFile + " " \
2013-08-25 23:28:25 +02:00
+ filesString \
2013-07-12 06:50:54 +02:00
+ self . file_finalAbstraction + " " \
2013-12-23 22:22:24 +01:00
+ self . get_staging_folder ( pkgName ) + " /src/R.java "
lutinMultiprocess . run_command ( cmdLine )
2013-04-23 21:48:36 +02:00
2013-12-23 22:22:24 +01:00
debug . print_element ( " pkg " , " .dex " , " <== " , " *.class " )
2013-11-06 21:13:30 +01:00
cmdLine = androidToolPath + " dx " \
2013-04-23 21:48:36 +02:00
+ " --dex --no-strict " \
2014-04-06 18:39:47 +02:00
+ " --output= " + self . get_staging_folder ( pkgName ) + " /build/ " + pkgNameApplicationName + " .dex " \
2013-12-23 22:22:24 +01:00
+ self . get_staging_folder ( pkgName ) + " /build/classes/ "
2014-04-06 18:39:47 +02:00
if " ADMOD_ID " in pkgProperties :
cmdLine + = self . folder_sdk + " /extras/google/google_play_services/libproject/google-play-services_lib/libs/google-play-services.jar "
2013-12-23 22:22:24 +01:00
lutinMultiprocess . run_command ( cmdLine )
2013-04-23 21:48:36 +02:00
2013-12-23 22:22:24 +01:00
debug . print_element ( " pkg " , " .apk " , " <== " , " .dex, assets, .so, res " )
2013-07-11 15:05:46 +02:00
#builderDebug="-agentlib:jdwp=transport=dt_socket,server=y,address=8050,suspend=y "
builderDebug = " "
2014-04-06 18:39:47 +02:00
# note : set -u not signed application...
#+ ":" + self.folder_sdk + "/extras/google/google_play_services/libproject/google-play-services_lib/libs/google-play-services.jar "
2013-07-11 15:05:46 +02:00
cmdLine = " java -Xmx128M " \
2014-04-06 18:39:47 +02:00
+ " -classpath " + self . folder_sdk + " /tools/lib/sdklib.jar " \
2013-07-11 15:05:46 +02:00
+ builderDebug \
2014-04-06 18:39:47 +02:00
+ " com.android.sdklib.build.ApkBuilderMain " \
+ self . get_staging_folder ( pkgName ) + " /build/ " + pkgNameApplicationName + " -unalligned.apk " \
+ " -u " \
+ " -z " + self . get_staging_folder ( pkgName ) + " /resources.res " \
+ " -f " + self . get_staging_folder ( pkgName ) + " /build/ " + pkgNameApplicationName + " .dex " \
+ " -rf " + self . get_staging_folder ( pkgName ) + " /data "
2013-12-23 22:22:24 +01:00
lutinMultiprocess . run_command ( cmdLine )
2013-04-23 21:48:36 +02:00
# doc :
# http://developer.android.com/tools/publishing/app-signing.html
2014-04-06 18:39:47 +02:00
# Create a key for signing your application:
# keytool -genkeypair -v -keystore AndroidKey.jks -storepass Pass__AndroidDebugKey -alias alias__AndroidDebugKey -keypass PassKey__AndroidDebugKey -keyalg RSA -validity 36500
2013-04-23 21:48:36 +02:00
if " debug " == self . buildMode :
tmpFile = open ( " tmpPass.boo " , ' w ' )
tmpFile . write ( " Pass__AndroidDebugKey \n " )
tmpFile . write ( " PassKey__AndroidDebugKey \n " )
tmpFile . flush ( )
tmpFile . close ( )
2013-12-23 22:22:24 +01:00
debug . print_element ( " pkg " , " .apk(signed debug) " , " <== " , " .apk (not signed) " )
2013-07-13 22:15:07 +02:00
# verbose mode :
#debugOption = "-verbose -certs "
debugOption = " "
2013-04-23 21:48:36 +02:00
cmdLine = " jarsigner " \
2013-07-13 22:15:07 +02:00
+ debugOption \
2013-12-23 22:22:24 +01:00
+ " -keystore " + lutinTools . get_current_path ( __file__ ) + " /AndroidDebugKey.jks " \
2014-04-06 18:39:47 +02:00
+ " -sigalg SHA1withRSA -digestalg SHA1 " \
+ self . get_staging_folder ( pkgName ) + " /build/ " + pkgNameApplicationName + " -unalligned.apk " \
+ " alias__AndroidDebugKey < tmpPass.boo "
2013-12-23 22:22:24 +01:00
lutinMultiprocess . run_command ( cmdLine )
2014-04-06 18:39:47 +02:00
tmpFile = open ( " tmpPass.boo " , ' w ' )
tmpFile . write ( " \n " )
tmpFile . flush ( )
tmpFile . close ( )
2013-04-23 21:48:36 +02:00
else :
2014-04-06 18:39:47 +02:00
print ( " On release mode we need the file : and key an pasword to sign the application ... " )
debug . print_element ( " pkg " , " .apk(signed debug) " , " <== " , " .apk (not signed) " )
cmdLine = " jarsigner " \
+ " -keystore " + basePkgPath + " /AndroidKey.jks " \
+ " -sigalg SHA1withRSA -digestalg SHA1 " \
+ self . get_staging_folder ( pkgName ) + " /build/ " + pkgNameApplicationName + " -unalligned.apk " \
+ " " + pkgNameApplicationName
lutinMultiprocess . run_command ( cmdLine )
cmdLine = " jarsigner " \
+ " -verify -verbose -certs " \
+ " -sigalg SHA1withRSA -digestalg SHA1 " \
+ self . get_staging_folder ( pkgName ) + " /build/ " + pkgNameApplicationName + " -unalligned.apk "
lutinMultiprocess . run_command ( cmdLine )
2013-04-23 21:48:36 +02:00
2013-12-23 22:22:24 +01:00
debug . print_element ( " pkg " , " .apk(aligned) " , " <== " , " .apk (not aligned) " )
2014-04-06 18:39:47 +02:00
lutinTools . remove_file ( self . get_staging_folder ( pkgName ) + " / " + pkgNameApplicationName + " .apk " )
2013-04-23 21:48:36 +02:00
# verbose mode : -v
cmdLine = self . folder_sdk + " /tools/zipalign 4 " \
2014-04-06 18:39:47 +02:00
+ self . get_staging_folder ( pkgName ) + " /build/ " + pkgNameApplicationName + " -unalligned.apk " \
+ self . get_staging_folder ( pkgName ) + " / " + pkgNameApplicationName + " .apk "
2013-12-23 22:22:24 +01:00
lutinMultiprocess . run_command ( cmdLine )
2013-04-23 21:48:36 +02:00
# copy file in the final stage :
2014-04-06 18:39:47 +02:00
lutinTools . copy_file ( self . get_staging_folder ( pkgName ) + " / " + pkgNameApplicationName + " .apk " ,
self . get_final_folder ( ) + " / " + pkgNameApplicationName + " .apk " ,
2014-06-18 11:52:01 +02:00
force = True )
2013-04-23 21:48:36 +02:00
2013-12-23 22:22:24 +01:00
def install_package ( self , pkgName ) :
2013-04-23 21:48:36 +02:00
debug . debug ( " ------------------------------------------------------------------------ " )
debug . info ( " Install package ' " + pkgName + " ' " )
debug . debug ( " ------------------------------------------------------------------------ " )
2014-04-06 18:39:47 +02:00
pkgNameApplicationName = pkgName
if " debug " == self . buildMode :
pkgNameApplicationName + = " debug "
2013-04-23 21:48:36 +02:00
cmdLine = self . folder_sdk + " /platform-tools/adb install -r " \
2014-04-06 18:39:47 +02:00
+ self . get_staging_folder ( pkgName ) + " / " + pkgNameApplicationName + " .apk "
2013-12-23 22:22:24 +01:00
lutinMultiprocess . run_command ( cmdLine )
2013-04-23 21:48:36 +02:00
2013-12-23 22:22:24 +01:00
def un_install_package ( self , pkgName ) :
2013-04-23 21:48:36 +02:00
debug . debug ( " ------------------------------------------------------------------------ " )
debug . info ( " Un-Install package ' " + pkgName + " ' " )
debug . debug ( " ------------------------------------------------------------------------ " )
2014-04-06 18:39:47 +02:00
pkgNameApplicationName = pkgName
if " debug " == self . buildMode :
pkgNameApplicationName + = " debug "
cmdLine = self . folder_sdk + " /platform-tools/adb uninstall " + pkgNameApplicationName
2013-07-11 13:53:19 +02:00
RlutinMultiprocess . unCommand ( cmdLine )
2013-04-23 21:48:36 +02:00
def Log ( self , pkgName ) :
debug . debug ( " ------------------------------------------------------------------------ " )
debug . info ( " logcat of android board " )
debug . debug ( " ------------------------------------------------------------------------ " )
cmdLine = self . folder_sdk + " /platform-tools/adb shell logcat "
2013-12-23 22:22:24 +01:00
lutinMultiprocess . run_command ( cmdLine )
2013-04-22 21:37:13 +02:00