diff --git a/build.sh b/build.sh index 9895164b7..632944a3c 100755 --- a/build.sh +++ b/build.sh @@ -147,7 +147,6 @@ cd project && env PATH=$NDKBUILDPATH BUILD_NUM_CPUS=$NCPU ndk-build -j$NCPU V=1 cd .. && ./copyAssets.sh && cd project && \ { if $build_release ; then \ $quick_rebuild && { \ - ln -s -f libs lib ; \ zip -u -r app/build/outputs/apk/release/app-release-unsigned.apk lib assets || exit 1 ; \ } || ./gradlew assembleRelease || exit 1 ; \ [ '!' -x jni/application/src/AndroidPostBuild.sh ] || { @@ -155,13 +154,22 @@ cd project && env PATH=$NDKBUILDPATH BUILD_NUM_CPUS=$NCPU ndk-build -j$NCPU V=1 ./AndroidPostBuild.sh `pwd`/../../../app/build/outputs/apk/release/app-release-unsigned.apk || exit 1 ; \ cd ../../.. ; \ } || exit 1 ; \ + ../copyAssets.sh pack-binaries app/build/outputs/apk/release/app-release-unsigned.apk ; \ rm -f app/build/outputs/apk/release/app-release.apk ; \ zipalign 4 app/build/outputs/apk/release/app-release-unsigned.apk app/build/outputs/apk/release/app-release.apk || exit 1 ; \ apksigner sign --ks ~/.android/debug.keystore --ks-key-alias androiddebugkey --ks-pass pass:android app/build/outputs/apk/release/app-release.apk || exit 1 ; \ else \ - ./gradlew assembleDebug && \ - mv -f app/build/outputs/apk/debug/app-debug.apk app/build/outputs/apk/release/app-release.apk \ - || exit 1 ; \ + ./gradlew assembleDebug || exit 1 ; \ + [ '!' -x jni/application/src/AndroidPostBuild.sh ] || { + cd jni/application/src ; \ + ./AndroidPostBuild.sh `pwd`/../../../app/build/outputs/apk/debug/app-debug.apk || exit 1 ; \ + cd ../../.. ; \ + } || exit 1 ; \ + mkdir -p app/build/outputs/apk/release ; \ + ../copyAssets.sh pack-binaries app/build/outputs/apk/debug/app-debug.apk && \ + zipalign 4 app/build/outputs/apk/debug/app-debug.apk app/build/outputs/apk/release/app-release.apk && + apksigner sign --ks ~/.android/debug.keystore --ks-key-alias androiddebugkey --ks-pass pass:android app/build/outputs/apk/release/app-release.apk || \ + mv -f app/build/outputs/apk/debug/app-debug.apk app/build/outputs/apk/release/app-release.apk || exit 1 ; \ fi ; } && \ { if $sign_apk; then cd .. && ./sign.sh && cd project ; else true ; fi ; } && \ { $install_apk && [ -n "`adb devices | tail -n +2`" ] && \ diff --git a/changeAppSettings.sh b/changeAppSettings.sh index 38db3d6e9..fee6c7e6d 100755 --- a/changeAppSettings.sh +++ b/changeAppSettings.sh @@ -1073,6 +1073,9 @@ fi if [ -e project/jni/application/src/project.patch ]; then patch -p1 --dry-run -f -R < project/jni/application/src/project.patch > /dev/null 2>&1 || patch -p1 --no-backup-if-mismatch < project/jni/application/src/project.patch || exit 1 ; fi +rm -f project/lib +ln -s -f libs project/lib + echo Cleaning up dependencies rm -rf project/libs/*/* project/gen diff --git a/copyAssets.sh b/copyAssets.sh index 80412243d..49616602b 100755 --- a/copyAssets.sh +++ b/copyAssets.sh @@ -1,16 +1,25 @@ #!/bin/sh +ARCHES="arm64-v8a armeabi-v7a x86 x86_64" + +if [ "$1" = "pack-binaries" ]; then +echo "Copying binaries.zip to .apk file" +COPIED=1 +for ARCH in $ARCHES; do + [ -e lib/$ARCH/binaries.zip ] && zip "$2" lib/$ARCH/binaries.zip && COPIED=0 +done +exit $COPIED +fi + echo "Copying app data files from project/jni/application/src/AndroidData to project/assets" mkdir -p project/assets rm -f -r project/assets/* if [ -d "project/jni/application/src/AndroidData" ] ; then cp -L -r project/jni/application/src/AndroidData/* project/assets/ - exit 0 # Do not split assets, this was needed only for Andorid 2.3 with it's stupid limitations - for F in project/assets/*; do - if [ `cat $F | wc -c` -gt 1000000 ] ; then - echo "The file $F is bigger than 1 megabyte - splitting it into smaller chunks" - split -b 1000000 -a 3 -d $F $F && rm $F || { echo "Error: 'split' command not installed" ; exit 1 ; } - fi - done fi + +for ARCH in $ARCHES; do + mv project/assets/binaries-$ARCH.zip project/libs/$ARCH/binaries.zip 2>/dev/null +done + exit 0 diff --git a/project/java/MainActivity.java b/project/java/MainActivity.java index 8aab7b017..607eaccb4 100644 --- a/project/java/MainActivity.java +++ b/project/java/MainActivity.java @@ -97,6 +97,8 @@ import android.app.UiModeManager; import android.Manifest; import android.content.pm.PermissionInfo; import java.util.Arrays; +import java.util.zip.ZipFile; +import java.util.ArrayList; public class MainActivity extends Activity @@ -1309,38 +1311,56 @@ public class MainActivity extends Activity } } + ZipFile myApk = null; + try + { + myApk = new ZipFile(getPackageResourcePath()); + } + catch( IOException eeeeeeeee ) {} + String [] binaryZipNames = { "binaries-" + android.os.Build.CPU_ABI + ".zip", "binaries-" + android.os.Build.CPU_ABI2 + ".zip", "binaries.zip" }; - if ( android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.JELLY_BEAN ) - binaryZipNames = new String[] { "binaries-" + android.os.Build.CPU_ABI + "-pie.zip", "binaries-" + android.os.Build.CPU_ABI2 + "-pie.zip", "binaries-" + android.os.Build.CPU_ABI + ".zip", "binaries-" + android.os.Build.CPU_ABI2 + ".zip", "binaries.zip" }; - for(String binaryZip: binaryZipNames) + if ( android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.LOLLIPOP ) + { + ArrayList a = new ArrayList(); + for( String arch: android.os.Build.SUPPORTED_ABIS ) + { + a.add("binaries-" + arch + ".zip"); + } + a.add("binaries.zip"); + binaryZipNames = a.toArray(new String[0]); + } + for( String binaryZip: binaryZipNames ) { try { - Log.i("SDL", "libSDL: Trying to extract binaries from assets " + binaryZip); - InputStream in = null; try { - for( int i = 0; ; i++ ) - { - InputStream in2 = getAssets().open(binaryZip + String.format("%02d", i)); - if( in == null ) - in = in2; - else - in = new SequenceInputStream( in, in2 ); - } + //Log.i("SDL", "libSDL: Trying to extract binaries from assets/" + binaryZip); + if( in == null ) + in = getAssets().open(binaryZip); + Log.i("SDL", "libSDL: Found binaries at assets/" + binaryZip); } - catch( IOException ee ) + catch( Exception eee ) {} + + if( binaryZip.equals("binaries.zip") ) { - try + for( String arch: android.os.Build.SUPPORTED_ABIS ) { - if( in == null ) - in = getAssets().open(binaryZip); + try + { + if( in == null && myApk != null ) + { + //Log.i("SDL", "libSDL: Trying to extract binaries from lib/" + arch + "/" + binaryZip); + in = myApk.getInputStream(myApk.getEntry("lib/" + arch + "/" + binaryZip)); + Log.i("SDL", "libSDL: Found binaries at lib/" + arch + "/" + binaryZip); + } + } + catch( Exception eeee ) {} } - catch( IOException eee ) {} } if( in == null ) - throw new RuntimeException("libSDL: Extracting binaries failed, the .apk file packaged incorrectly"); + throw new RuntimeException("libSDL: Extracting binaries failed"); ZipInputStream zip = new ZipInputStream(in); @@ -1354,10 +1374,8 @@ public class MainActivity extends Activity { ZipEntry entry = null; entry = zip.getNextEntry(); - /* - if( entry != null ) - Log.i("SDL", "Extracting lib " + entry.getName()); - */ + //if( entry != null ) + // Log.i("SDL", "Extracting binary " + entry.getName()); if( entry == null ) { Log.i("SDL", "Extracting binaries finished"); @@ -1373,13 +1391,16 @@ public class MainActivity extends Activity OutputStream out = null; String path = libDir.getAbsolutePath() + "/" + entry.getName(); - try { + try + { File outDir = new File( path.substring(0, path.lastIndexOf("/") )); if( !(outDir.exists() && outDir.isDirectory()) ) outDir.mkdirs(); - } catch( SecurityException eeeeeee ) { }; + } + catch( SecurityException eeeeeee ) { }; - try { + try + { CheckedInputStream check = new CheckedInputStream( new FileInputStream(path), new CRC32() ); while( check.read(buf, 0, buf.length) > 0 ) {}; check.close(); @@ -1417,6 +1438,12 @@ public class MainActivity extends Activity //Log.i("SDL", "libSDL: Error: " + eee.toString()); } } + try + { + if (myApk != null) + myApk.close(); + } + catch( IOException eeeeeeeeee ) {} }; public static String GetMappedLibraryName(final String s)