Android App Bundle (only) - native library failed to load - android

I switched to Android App Bundle (ABB) in Google Play production few months ago and released couple updates - things were fine. Last week I took Android Studio update and noticed that ONLY the ABB build fails to load one of my native library at runtime. However APK build (release) and debug build is loading the native library fine.
I was forced to deploy an APK to replace the broken ABB release in production.
I found the ABB package contains all four (arm64-v8a, armeabi-v7a, x86, x86_64) directories and all my .SO files are in there (same as in the APK package).
For further investigation, I edited the Android Studio Run Configuration to deploy 'APK from app bundle' and verified the native library is failing to load for ABB build only (other build modes are fine).
My environment: Android Studio 4.0 (latest at the moment),
'io.fabric.tools:gradle:1.28.0' (ABB worked until 1.26.1),
compileSdkVersion 28,
buildToolsVersion '28.0.3'
There is no easy way to rollback latest update. Please let me know how to fix this build issue. Appreciate your help.

Finally found the workaround to resolve this issue. The third-party library that I am using is not compliant with the recent Gradle change. Java code of the library doesn't know the right path to it's SO file when an APK is constructed from ABB on a device. Setting in the gradle.properties file works well.
According to the Gradle release note
When building an Android App Bundle, APKs generated from that app
bundle that target Android 6.0 (API level 23) or higher now include
uncompressed versions of your native libraries by default. This
optimization avoids the need for the device to make a copy of the
library and thus reduces the on-disk size of your app. If you'd rather
disable this optimization, add the following to your gradle.properties
file:
android.bundle.enableUncompressedNativeLibs = false

Related

I can not build android app aab format and api 30 in Quasar

I don't have much experience.
I'm trying to build an aab app for android api 30.
Can I please see somewhere what version Gradle and Cordova must be in?
I am trying to use the Cordova version here:
https://cordova.apache.org/announcements/2021/07/20/cordova-android-10.0.0.html?
I'm trying it on the default quasar project
quasar 3.2.4
node 16.13.1
java version "17.0.1" 2021-10-19 LTS
android studio 2020.3.1. patch 3 - sdk 14-31
But build still failed.
Can someone please direct me to a workable procedure please?
screenshot from console: https://ibb.co/hdxyHGf
I struggled with this my self for couple of days. I will try to answer it as detailed as I can. Maybe you will find some problems that are dependent on your application, but at least you will have something to work with.
As I can understand you have a quasar application that is using cordova and you want to build Android App Bundle (.aab) file to publish it to the Google Play Store, because now play store accepts only .aab files.
First quasar as a framework has nothing to do with this. Quasar framework just builds your web app and the build output is stored in src-cordova/www folder. It doesn't matter if you are using Quasar v1 or v2.
Cordova is a framework that will create the whole project structure (android / iOS) a.k.a cordova platforms and run the specific build tools to build the poject using command lines (gradle cli / xcode cli).
To build .aab file for Google Play Store you will also need to target Android API level 30. Cordova version that supports android API level 30 is version 10. I am using cordova-android-v10.0.0.
To install cordova-android-v10, first you will need to remove the android platform you have now i.e. src-cordova/platforms/android folder. After that navigate in src-cordova folder. And install cordova android platform v10 with following command cordova platform add android#10.0.0.
Now you will need to build the android project using gradle. Cordova android v10 needs gradle v7.1.1.
To find more about cordova android v10.0.0 and its compatible versions with other tools like gradle you can see the following link: https://cordova.apache.org/announcements/2021/07/20/cordova-android-10.0.0.html
You can download gradle v7.1.1 from the following link: https://gradle.org/releases/. I recommend downloading the complete package i.e. gradle-v7.1.1-all.zip.
Unpack the zip file in C:/Gradle/gradle-v7.1.1 if you are using windows. If you are using macOS I think you should extract it in /Library/Gradle/gradle-v7.1.1.
After that you will need to add GRADLE_HOME environment variable (GRADLE_HOME=C:/Gradle/gradle-v7.1.1) and add gradle bin directory to the PATH i.e. PATH=...,%GRADLE_HOME%\bin.
Check if you have installed gradle successfully with gradle -v command in terminal to see the gradle version
Now you should be able to build the android cordova project with gradle. Go to src-cordova/aplatforms/android and execute gradle build. If everything is ok you can go to your root project folder end execute npm run build:android.
If everything passes you will see app-release.aab file in dist/cordova/android output folder.
IMPORTANT: There are couple of caveats that I want to point them out which will lead to unsuccessful build.
First is the cordova android API level compatibility. Cordova v10.0.0 supports from API level 22 to API level 30. You will need to add the following xml in your cordova config.xml:
<platform name="android">
<!-- other settings -->
<preference name="android-minSdkVersion" value="22" />
<preference name="android-targetSdkVersion" value="30" />
<!-- other settings -->
</platform>
Following link gives you the supported API levels for android cordova and its versions: https://cordova.apache.org/docs/en/latest/guide/platforms/android/index.html#requirements-and-support
If you do not add minSdkVersion 22 you will have problems with MultiDex support. This is due to that API level 22 (Android 5.1) by default enables multi DEX files applications. If you min target below 22 you will have exceptions like:
java.lang.RuntimeException: Unable to instantiate application android.support.multidex.MultiDexApplication
There is a workaround for this but I will not get into it here. You can read more on this link: https://developer.android.com/studio/build/multidex#mdex-pre-l
Second you need to generate your keystore file if you have not done that already and configure the build.json file. In build.json file you can define output packages for release and debug. In my project I have set them: debug to output apk and release to output aab file and also you can define the keystore file path.
You can find more about build.json on the following link: https://cordova.apache.org/docs/en/latest/guide/platforms/android/index.html#using-buildjson
Third thing is subjective, but I want to point it here because I think it might help. The 3rd thing are plugins. Many plugins are old (more that 3 years) and might not work with this new setup due to errors when trying to build them with gradle build command. I used qrscanner plugin in my app (cordova-plugin-qrscanner) which failed to build because of Androidx and support libraries. You can find more about this issue https://github.com/bitpay/cordova-plugin-qrscanner/issues/360. At the end I used new androidx qrscanner plugins.
# inside src-cordova folder
cordova plugin add cordova-plugin-qrscanner-androidx --save
cordova plugin add cordova-plugin-androidx-adapter --save
If you have troubles like this remove src-cordova/plugins folder and do cordova build android in src-cordova folder to reinstall all plugins. If error pops out try to install replacement plugin for the one that is failing.
Sorry for the long answer but this kind of problems are hard to explain, especially when using framework that uses framework, that uses framework....

Move third party library file from armaebi-v7a folder to armaebi built folder

Recently I have upgraded firebase crashlytics SDK to version 17.2.1 (NDK-version). This provide third party library libcrashlytics.so for artitecture armeabi-v7a and arm64-v8a for arm based 32-bit devices and 64-bit drvices. But my app is built for armeabi architecture for 32-bit devices and not for armaebi-v7a.
So post app build, when all the libraries are merged by build gradle, I cannot see libcrashlytics.so library in armeabi folder.
...build/intermediates/merged_native_libs/.../out/lib/armeabi-v7a/libcrashlytics.so
...build/intermediates/merged_native_libs/.../out/lib/arm64-v8a/libcrashlytics.so
...build/intermediates/stripped_native_libs/.../out/lib/armeabi-v7a/libcrashlytics.so
...build/intermediates/stripped_native_libs/.../out/lib/arm64-v8a/libcrashlytics.so
So when I try to dlopen this library with dlopen("libcrashlytics.so", RTLD_LAZY | RTLD_LOCAL)); my app crashes in 32-bit mobile devices as it is not able to load libcrashlytics library. My app works fine with 64-bit architecture.
But after manually copying libcrashlytics.so library to ...build/intermediates/stripped_native_libs/.../out/lib/armaebi/ directory and then building it, solves the problem. In https://developer.android.com/ndk/guides/abis it is mentioned that armaebi-v7a is compatible with armaebi, so it should be fine.
So,
Is there any way to provide instruction to gradle to copy "libcrashlytics.so" located in armaebi-v7a to armaebi ?
Is there any other way to automate copying during build ?
Is there any other work around for my problem ?
Environment -
Gradle plugin version - 3.5.4
Gradle version - 5.4.1
NOTE: Due to few other reasons, I cannot move our app to support "armaebi-v7a"

Is the platform required to compile and build Android apk

I have set up a Concourse CI pipeline to run tests and build my apk. I've built a docker image for my job to run in. The image contains the sdk tools, build tools and platform tools but does not contain the platform that corresponds to the compileSdkVersion. It seems to work and build the apk correctly, I can run the apk on a device. I'm slightly confused by this as I would have thought that the platform would be required. Does anybody know how this is working under the hood and what the minimum set of files are required to compile and build the apk?
Thanks
It turns out that gradle actually pulls down the platform during the build, I noticed it in the logs.

Differences of Android apk exported by Eclipse and Android Studio

What are the differences of apk from Eclipse and Android Studio[IntelliJ IDEA]
is there more security in Android Studio build?
Android Studio utilizes the fast growing Gradle build system. It builds on top of the concepts of Apache Ant and Apache Maven but it also introduces a Groovy DSL (Domain-Specific Language) that allows for scripted builds which opens up many automation possibilities like uploading your beta .apk to TestFlight for testing.
Eclipse on the other hand uses Apache Ant as its main build system which a very robust XML based build system .
Please check this SO Answer
ADT (Eclipse) vs. Android Studio: How much APK file size difference is normal?
Conclusion
Both are identical.But i prefer Android Studio.
They both use the Android SDK to generate the APKs, they should be identical.
Code protection (security by obfuscation) is done with ProGuard both on Android Studio and on ADT (Eclipse). So if you use ProGuard, there should be no difference.

ADT (Eclipse) vs. Android Studio: How much APK file size difference is normal?

I imported a ADT project to the latest version of Android Studio (0.6.1). Both projects share the same code and libraries. Also both projects were cleared and compiled with the same ProGuard settings enabled.
But the size of the ADT APK file is 1.8 MB and the Android Studio APK file is 2.7 MB.
Is this increase of 50% in APK file size considered as normal due to the fact that Android Studio is still in Early Access Preview or should I be able to get nearly the same APK file size?
(Update: I just unzipped the APK file: All files are nearly the same size, but the difference comes from the classes.dex file which is 1.2 MB on ADT and 4.4 MB on Android Studio.)
By reverse engineering the classes.dex files I found out that my code wasn't obfuscated in Android Studio.
Even though it seemed to me that ProGuard was enabled via runProguard true in my build.gradle and the checkbox asking for ProGuard before generating the signed APK file.
I had to change the build variant of the app module from debug to release as described here.
Now both APK files are almost the same size (1.812 vs. 1.817 MB).

Categories

Resources