def apk(self, toolchain, writer, module, archbins, javasources, outpath, binname, basepath, config, implicit_deps, resources): buildpath = os.path.join('$buildpath', config, 'apk', binname) baseapkname = binname + ".base.apk" unsignedapkname = binname + ".unsigned.apk" unalignedapkname = binname + ".unaligned.apk" apkname = binname + ".apk" apkfiles = [] libfiles = [] locallibs = [] resfiles = [] manifestfile = [] writer.comment('Make APK') for _, value in archbins.iteritems(): for archbin in value: archpair = os.path.split(archbin) libname = archpair[1] arch = os.path.split(archpair[0])[1] locallibpath = os.path.join('lib', self.archpath[arch], libname) archpath = os.path.join(buildpath, locallibpath) locallibs += [locallibpath + ' '] libfiles += toolchain.copy(writer, archbin, archpath) for resource in resources: filename = os.path.split(resource)[1] if filename == 'AndroidManifest.xml': manifestfile = toolchain.copy( writer, os.path.join(basepath, module, resource), os.path.join(buildpath, 'AndroidManifest.xml')) else: restype = os.path.split(os.path.split(resource)[0])[1] if restype == 'asset': pass #todo: implement else: resfiles += toolchain.copy( writer, os.path.join(basepath, module, resource), os.path.join(buildpath, 'res', restype, filename)) #Make directories gendir = toolchain.mkdir(writer, os.path.join(buildpath, 'gen')) bindir = toolchain.mkdir(writer, os.path.join(buildpath, 'bin')) binresdir = toolchain.mkdir(writer, os.path.join(buildpath, 'bin', 'res'), order_only=bindir) alldirs = gendir + bindir + binresdir aaptvars = [('apkbuildpath', buildpath), ('apk', baseapkname)] aaptout = os.path.join(buildpath, baseapkname) if config == 'deploy': baseapkfile = writer.build(aaptout, 'aaptdeploy', manifestfile, variables=aaptvars, implicit=manifestfile + resfiles, order_only=alldirs) else: baseapkfile = writer.build(aaptout, 'aapt', manifestfile, variables=aaptvars, implicit=manifestfile + resfiles, order_only=alldirs) #Compile java code javafiles = [] localjava = [] if javasources != []: #self.javaccmd = '$javac -d $outpath -classpath $outpath -sourcepath $sourcepath -target 1.5 -bootclasspath $androidjar -g -source 1.5 -Xlint:-options $in' #self.dexcmd = '$dex --dex --output $out $in' javasourcepath = '.' if self.host.is_windows(): javasourcepath += ';' else: javasourcepath += ':' javasourcepath += os.path.join(buildpath, 'gen') classpath = os.path.join(buildpath, 'classes') javavars = [('outpath', classpath), ('sourcepath', javasourcepath)] javaclasses = writer.build(classpath, 'javac', javasources, variables=javavars, implicit=baseapkfile) localjava += ['classes.dex'] javafiles += writer.build(os.path.join(buildpath, 'classes.dex'), 'dex', classpath) #Add native libraries and java classes to apk aaptvars = [('apkbuildpath', buildpath), ('apk', unsignedapkname), ('apksource', baseapkname), ('apkaddfiles', toolchain.paths_forward_slash(locallibs + localjava))] unsignedapkfile = writer.build(os.path.join(buildpath, unsignedapkname), 'aaptadd', baseapkfile, variables=aaptvars, implicit=libfiles + javafiles, order_only=alldirs) #Sign the APK codesignvars = [('config', config)] unalignedapkfile = writer.build(os.path.join(buildpath, unalignedapkname), 'codesign', unsignedapkfile, variables=codesignvars) #Run zipalign outfile = writer.build(os.path.join(outpath, config, apkname), 'zipalign', unalignedapkfile) return outfile
def apk(self, toolchain, writer, module, archbins, javasources, outpath, binname, basepath, config, implicit_deps, resources): buildpath = os.path.join('$buildpath', config, 'apk', binname) baseapkname = binname + ".base.apk" unsignedapkname = binname + ".unsigned.apk" unalignedapkname = binname + ".unaligned.apk" apkname = binname + ".apk" apkfiles = [] libfiles = [] locallibs = [] resfiles = [] manifestfile = [] writer.comment('Make APK') for _, value in archbins.iteritems(): for archbin in value: archpair = os.path.split(archbin) libname = archpair[1] arch = os.path.split(archpair[0])[1] locallibpath = os.path.join('lib', self.archpath[arch], libname) archpath = os.path.join(buildpath, locallibpath) locallibs += [locallibpath + ' '] libfiles += toolchain.copy(writer, archbin, archpath) for resource in resources: filename = os.path.split(resource)[1] if filename == 'AndroidManifest.xml': manifestfile = toolchain.copy(writer, os.path.join(basepath, module, resource), os.path.join(buildpath, 'AndroidManifest.xml')) else: restype = os.path.split(os.path.split(resource)[0])[1] if restype == 'asset': pass #todo: implement else: resfiles += toolchain.copy(writer, os.path.join(basepath, module, resource), os.path.join(buildpath, 'res', restype, filename)) #Make directories gendir = toolchain.mkdir(writer, os.path.join(buildpath, 'gen')) bindir = toolchain.mkdir(writer, os.path.join(buildpath, 'bin')) binresdir = toolchain.mkdir(writer, os.path.join(buildpath, 'bin', 'res'), order_only = bindir) alldirs = gendir + bindir + binresdir aaptvars = [('apkbuildpath', buildpath), ('apk', baseapkname)] aaptout = os.path.join(buildpath, baseapkname) if config == 'deploy': baseapkfile = writer.build(aaptout, 'aaptdeploy', manifestfile, variables = aaptvars, implicit = manifestfile + resfiles, order_only = alldirs) else: baseapkfile = writer.build(aaptout, 'aapt', manifestfile, variables = aaptvars, implicit = manifestfile + resfiles, order_only = alldirs) #Compile java code javafiles = [] localjava = [] if javasources != []: #self.javaccmd = '$javac -d $outpath -classpath $outpath -sourcepath $sourcepath -target 1.5 -bootclasspath $androidjar -g -source 1.5 -Xlint:-options $in' #self.dexcmd = '$dex --dex --output $out $in' javasourcepath = '.' if self.host.is_windows(): javasourcepath += ';' else: javasourcepath += ':' javasourcepath += os.path.join(buildpath, 'gen') classpath = os.path.join(buildpath, 'classes') javavars = [('outpath', classpath), ('sourcepath', javasourcepath)] javaclasses = writer.build(classpath, 'javac', javasources, variables = javavars) localjava += ['classes.dex'] javafiles += writer.build(os.path.join(buildpath, 'classes.dex'), 'dex', classpath) #Add native libraries and java classes to apk aaptvars = [('apkbuildpath', buildpath), ('apk', unsignedapkname), ('apksource', baseapkname), ('apkaddfiles', toolchain.paths_forward_slash(locallibs + localjava))] unsignedapkfile = writer.build(os.path.join(buildpath, unsignedapkname), 'aaptadd', baseapkfile, variables = aaptvars, implicit = libfiles + javafiles, order_only = alldirs) #Sign the APK jarsignervars = [] if self.tsacert != '': jarsignervars += [('timestamp', '-tsacert ' + self.tsacert)] elif self.tsa != '': jarsignervars += [('timestamp', '-tsa ' + self.tsa)] unalignedapkfile = writer.build(os.path.join(buildpath, unalignedapkname), 'jarsigner', unsignedapkfile, variables = jarsignervars) #Run zipalign outfile = writer.build(os.path.join(outpath, config, apkname), 'zipalign', unalignedapkfile) return outfile