airsdk / Adobe-Runtime-Support

Report, track and discuss issues in Adobe AIR. Monitored by Adobe - and HARMAN - and maintained by the AIR community.
199 stars 11 forks source link

[ANDROID] WISH: reducing APK size not including ANE's source files #682

Open Oldes opened 3 years ago

Oldes commented 3 years ago

Problem Description

When using native extensions, currently all ANE's sources are included in builded APK. That may be quite a lot of MBs. For example in my local test with basic Google API ANE for handling Google Play connectivity, the APK made using the latest AIR has 22MB, but when I manually delete ANE's related resources and JARs, I'm able to reduce the APK to just 12MB (and have the app fully functional).

Although I can achieve this reduction by additional build steps:

  1. unzip APK,
  2. delete not required files from APK,
  3. zip and zipalign the APK,
  4. resign the APK

it would be really nice if the AIR build process was clever enough not including these source files in the target APK by default.

Oldes commented 3 years ago

Here is a Windows' script which I'm now using:

:: This script is for ARM64 version, for 32bit, the extension folder is `Android-ARM` instead of Android-ARM64
@SET APK=TestAndroidGooglePlayANE-ARM64.apk
@SET BUILD_TOOLS=C:\SDKs\Android-sdk\build-tools\29.0.3
@SET EXT_GOOGLE=assets\META-INF\AIR\extensions\com.our.GoogleExtension\META-INF\ANE\Android-ARM64
@SET TMP_APK=tmp_%APK%
@SET NEW_APK=new_%APK%

@PUSHD Build
@DEL   %NEW_APK%

@MKDIR temp
@PUSHD temp

@ECHO =================================================================================
@ECHO Extracting APK...
::
:: UNZIP or 7Zip may be used for better speed, but JAR is compatible way
::
JAR xf ../%APK%

@ECHO =================================================================================
@ECHO Removing unneeded files...
::
:: It looks that only `library.swf` file cannot be deleted
::
MOVE  %EXT_GOOGLE%\library.swf .\
RMDIR %EXT_GOOGLE% /S/Q
MKDIR %EXT_GOOGLE%
MOVE  library.swf %EXT_GOOGLE%\
::
:: Other extensions may be cleaned as the one above
::

@ECHO =================================================================================
@ECHO Packing back to APK...
JAR cf ../%TMP_APK% .

@POPD
@ECHO =================================================================================
@ECHO Zipalign and resign...
%BUILD_TOOLS%\zipalign.exe 4 %TMP_APK% %NEW_APK%
CALL %BUILD_TOOLS%\apksigner.bat sign --ks ..\TestAndroidGooglePlayANE.p12 --ks-pass pass:<some_passwd> %NEW_APK%
CALL %BUILD_TOOLS%\apksigner.bat verify --verbose %NEW_APK%

@ECHO =================================================================================
@ECHO Clean temps...
@RMDIR temp /s /q
@DEL %TMP_APK%

@POPD
@ECHO Done: %NEW_APK%
Elintondm commented 3 years ago

Nice!!!

How do you know what can be deleted?

Em seg., 8 de fev. de 2021 às 14:02, Oldes Huhuman notifications@github.com escreveu:

Here is a Windows' script which I'm now using:

:: This script is for ARM64 version, for 32bit, the extension folder is Android-ARM instead of Android-ARM64 @SET APK=TestAndroidGooglePlayANE-ARM64.apk @SET BUILD_TOOLS=C:\SDKs\Android-sdk\build-tools\29.0.3 @SET EXT_GOOGLE=assets\META-INF\AIR\extensions\com.our.GoogleExtension\META-INF\ANE\Android-ARM64 @SET TMPAPK=tmp%APK% @SET NEWAPK=new%APK%

@PUSHD Build @DEL %NEW_APK%

@MKDIR temp @PUSHD temp

@ECHO ================================================================================= @ECHO Extracting APK... :: :: UNZIP or 7Zip may be used for better speed, but JAR is compatible way :: JAR xf ../%APK%

@ECHO ================================================================================= @ECHO Removing unneeded files... :: :: It looks that only library.swf file cannot be deleted :: MOVE %EXT_GOOGLE%\library.swf .\ RMDIR %EXT_GOOGLE% /S/Q MKDIR %EXT_GOOGLE% MOVE library.swf %EXT_GOOGLE%\ :: :: Other extensions may be cleaned as the one above ::

@ECHO ================================================================================= @ECHO Packing back to APK... JAR cf ../%TMP_APK% .

@POPD @ECHO ================================================================================= @ECHO Zipalign and resign... %BUILD_TOOLS%\zipalign.exe 4 %TMP_APK% %NEW_APK% CALL %BUILD_TOOLS%\apksigner.bat sign --ks ..\TestAndroidGooglePlayANE.p12 --ks-pass pass: %NEW_APK% CALL %BUILD_TOOLS%\apksigner.bat verify --verbose %NEW_APK%

@ECHO ================================================================================= @ECHO Clean temps... @RMDIR temp /s /q @DEL %TMP_APK%

@POPD @ECHO Done: %NEW_APK%

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/Gamua/Adobe-Runtime-Support/issues/682#issuecomment-775292754, or unsubscribe https://github.com/notifications/unsubscribe-auth/AFCZGYIW2Q7T4POXHPFZVH3S6AKKFANCNFSM4XE67QXA .