I have developed my application in react native. I want to minify and shrink my code. In order to achieve this I have enabled proguard and added proguard based lines in build.gradle
Here's my code
build.gradle
android {
compileSdkVersion 23
buildToolsVersion '26.0.2'
defaultConfig {
applicationId "com.mobile"
minSdkVersion 16
targetSdkVersion 22
versionCode 1
versionName "1.0"
ndk {
abiFilters "armeabi-v7a", "x86"
}
}
signingConfigs {
release {
if (project.hasProperty('MYAPP_RELEASE_STORE_FILE')) {
storeFile file(MYAPP_RELEASE_STORE_FILE)
storePassword MYAPP_RELEASE_STORE_PASSWORD
keyAlias MYAPP_RELEASE_KEY_ALIAS
keyPassword MYAPP_RELEASE_KEY_PASSWORD
}
}
}
buildTypes {
release {
debuggable false
minifyEnabled true
shrinkResources true
signingConfig signingConfigs.release
// minifyEnabled enableProguardInReleaseBuilds
proguardFiles getDefaultProguardFile("proguard-android.txt"), "proguard-rules.pro"
}
}
splits {
abi {
reset()
enable enableSeparateBuildPerCPUArchitecture
universalApk false // If true, also generate a universal APK
include "armeabi-v7a", "x86"
}
}
// buildTypes {
// release {
// minifyEnabled enableProguardInReleaseBuilds
// proguardFiles getDefaultProguardFile("proguard-android.txt"), "proguard-rules.pro"
// }
// }
// applicationVariants are e.g. debug, release
applicationVariants.all { variant ->
variant.outputs.each { output ->
// For each separate APK per architecture, set a unique version code as described here:
// http://tools.android.com/tech-docs/new-build-system/user-guide/apk-splits
def versionCodes = ["armeabi-v7a":1, "x86":2]
def abi = output.getFilter(OutputFile.ABI)
if (abi != null) { // null for the universal-debug, universal-release variants
output.versionCodeOverride =
versionCodes.get(abi) * 1048576 + defaultConfig.versionCode
}
}
}
}
Im getting this error.
Execution failed for task ':app:transformClassesAndResourcesWithProguardForRelease'
Im not sure where its going wrong. Please guide me so that I can resolve this issue.
You probably get some warnings from ProGuard.
Try to enable setting -i when running your gradle build to see the warnings.
You can also test this hypothesis by adding -ignorewarnings to your ProGuard configuration. If the build succeeds afterwards if was due to the mentioned warnings.
Note: you should investigate these warnings and fix them if possible (some are harmless), otherwise your application might contain errors and will not function properly at runtime.
Related
I'm running into an odd issue and not at all sure why.
I'm using firebase app distribution to install development-grade versions of my app and whenever I try to install a dev version of my app, it won't install claiming that the app exists already, but it doesn't.
I have the app from the store installed and upon uninstalling that, the app will then install but I don't understand why as both have different applicationIds.
the store version has: com.example.myapp & the dev version has com.example.myapp.preview and the app name is also different as is the version code and version name.
I don't get what they seem to share that is causing it to not allow both of them to coexist.
Not sure if this is important, but when I try to install the dev version, play protect will pop-up claiming the app is unknown and to be sure you trust it.
I'm hoping someone can steer me in a direction on solving this as I'm simply lost on what's causing the conflict.
here is the relevant gradle config:
android {
compileSdk 32
defaultConfig {
applicationId "com.example.myppp"
targetSdkVersion 32
minSdkVersion 26
versionCode verCode
versionName "4.2.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
signingConfigs {
development {
storeFile file("../keystore/development.jks")
storePassword System.getenv("DEV_SIGNING_STORE_PASSWORD")
keyAlias System.getenv("DEV_SIGNING_KEY_ALIAS")
keyPassword System.getenv("DEV_SIGNING_KEY_PASSWORD")
}
debug {
storeFile file("../keystore/debug.jks")
storePassword System.getenv("DEBUG_SIGNING_STORE_PASSWORD")
keyAlias System.getenv("DEBUG_SIGNING_KEY_ALIAS")
keyPassword System.getenv("DEBUG_SIGNING_KEY_PASSWORD")
}
release {
storeFile file("../keystore/prod.jks")
storePassword System.getenv("PROD_SIGNING_STORE_PASSWORD")
keyAlias System.getenv("PROD_SIGNING_KEY_ALIAS")
keyPassword System.getenv("PROD_SIGNING_KEY_PASSWORD")
}
}
buildTypes {
development {
versionNameSuffix "-DEV"
minifyEnabled false
applicationIdSuffix '.preview'
debuggable true
signingConfig signingConfigs.development
firebaseCrashlytics {
mappingFileUploadEnabled false
}
}
debug {
versionNameSuffix "-DEBUG"
minifyEnabled false
applicationIdSuffix '.debug'
signingConfig signingConfigs.debug
firebaseCrashlytics {
mappingFileUploadEnabled false
}
}
release {
signingConfig signingConfigs.release
// Enables code shrinking, obfuscation, and optimization for only your project's release build type.
minifyEnabled true
// Enables resource shrinking, which is performed by the Android Gradle plugin.
shrinkResources true
// Includes the default ProGuard rules files that are packaged with the Android Gradle plugin.
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
// Makes crash reports readable
// #see https://firebase.google.com/docs/crashlytics/get-deobfuscated-reports?platform=android
firebaseCrashlytics {
mappingFileUploadEnabled true
}
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_11
targetCompatibility JavaVersion.VERSION_11
}
packagingOptions {
resources {
excludes += ['META-INF/*.kotlin_module']
}
}
kotlinOptions {
jvmTarget = '11'
freeCompilerArgs += "-opt-in=kotlin.RequiresOptIn"
}
buildFeatures {
viewBinding true
}
lint {
abortOnError true
}
}
I have discovered my issue, it appears I was reusing the same file provider identifier, I made that more dependent on the application id and now I'm able to install the dev app alongside my store version.
I also has add product flavors as I saw a few SO answers claim that's a better way to go about what I was looking to do.
I have built a release android apk file, conceived for a size of 7.9 MB.
I manage to install it on my android device, but not to open it because it crashes.
When i use flutter run --release it still does not open and detects no errors.
How can I solve that problem?
Thank you for your help.
Note: I have found several questions close to mine, but they have an error or are not entirely similar to mine. As a consequence the solution given do not work on my case.
Here is some of my build.gradle
android {
compileSdkVersion 28
sourceSets {
main.java.srcDirs += 'src/main/kotlin'
}
lintOptions {
disable 'InvalidPackage'
checkReleaseBuilds false
}
defaultConfig {
// TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
applicationId "com.misteref.mykamus"
minSdkVersion 16
targetSdkVersion 28
versionCode flutterVersionCode.toInteger()
versionName flutterVersionName
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
signingConfigs {
release {
keyAlias keystoreProperties['keyAlias']
keyPassword keystoreProperties['keyPassword']
storeFile file(keystoreProperties['storeFile'])
storePassword keystoreProperties['storePassword']
}
}
buildTypes {
release {
signingConfig signingConfigs.release
useProguard true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
signingConfig signingConfigs.release
}
}
}
in app level build.gradle
set minifyEnabled and shrinkResources to false
or use progaurd if you need this two be true
buildTypes {
release {
signingConfig signingConfigs.release
minifyEnabled true
shrinkResources true
useProguard true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
To expand on #Joachim Haglund's comment
update your gradle file with the following. All the builds will then be included in the aab file. (It's also worth checking what SDKs you have installed/require updating with Android Studio)
android {
defaultConfig {
//add the following
ndk {
abiFilters "x86", "x86_64", "armeabi", "armeabi-v7a", "arm64-v8a"
}
}
}
I have a react-native app that runs with the react-native run-android command, but when I try to build the signed apk for release, the app crashes on some devices. Here is my build gradle:
android {
compileSdkVersion rootProject.ext.compileSdkVersion
buildToolsVersion rootProject.ext.buildToolsVersion
defaultConfig {
applicationId "com.mednetinternal"
minSdkVersion rootProject.ext.minSdkVersion
targetSdkVersion rootProject.ext.targetSdkVersion
versionCode 1
versionName "1.0"
ndk {
abiFilters "armeabi", "armeabi-v7a", "x86", "arm64-v8a"
}
}
signingConfigs {
release {
if (project.hasProperty('MYAPP_RELEASE_STORE_FILE')) {
storeFile file(MYAPP_RELEASE_STORE_FILE)
storePassword MYAPP_RELEASE_STORE_PASSWORD
keyAlias MYAPP_RELEASE_KEY_ALIAS
keyPassword MYAPP_RELEASE_KEY_PASSWORD
}
}
}
splits {
abi {
reset()
enable enableSeparateBuildPerCPUArchitecture
universalApk true // If true, also generate a universal APK
include "armeabi-v7a", "x86", "arm64-v8a"
}
}
buildTypes {
release {
minifyEnabled enableProguardInReleaseBuilds
proguardFiles getDefaultProguardFile("proguard-android.txt"), "proguard-rules.pro"
signingConfig signingConfigs.release
}
}
// applicationVariants are e.g. debug, release
applicationVariants.all { variant ->
variant.outputs.each { output ->
// For each separate APK per architecture, set a unique version code as described here:
// http://tools.android.com/tech-docs/new-build-system/user-guide/apk-splits
def versionCodes = ["armeabi-v7a":1, "x86":2, "arm64-v8a":3]
def abi = output.getFilter(OutputFile.ABI)
if (abi != null) { // null for the universal-debug, universal-release variants
output.versionCodeOverride =
versionCodes.get(abi) * 1048576 + defaultConfig.versionCode
}
}
}
I tried methods that other strings related to the same or similar questions mentioned, but nothing has worked. Upon extracting the universal apk, I found libimagepipeline.so as the only file in /lib/arm64-v8a, but adding an exclude statement for it in packagingOptions did not work either. Is there some way to make an apk that works on all devices?
The errors I have been getting are:
libgnustl_shared.so is 32-bit instead of 64-bit.
Could not find libreactnativejni.so
I have got android mobile app developed using React Native (not expo). I tested it on emulators (android and IOS) and it is working fine. I then released it to google play. I tested it on 3 devices:
1) One plus one - working fine
2) Samsung S8 - crashes
3) Samsung S7 - crashes
I found the reason why it crashes. Samsung is picking up app-arm64-v8a-release.apk while 1+1 is installing app-armeabi-v7a-release.apk through google play. If i manually download app-armeabi-v7a-release.apk on samsung phone (and not through google play) then the app works fine. Some questions:
1) Is Samsung supposed to download what it is downloading (app-arm64-v8a-release.apk)?
2) If yes (which i think is right) then what could be the issue? How i can debug a production app.
Note: App crashes if i manually install universal apk on 1+1 and Samsung phones.
this is my gradele.build file
def enableSeparateBuildPerCPUArchitecture = true
def enableProguardInReleaseBuilds = true
android {
compileSdkVersion rootProject.ext.compileSdkVersion
buildToolsVersion rootProject.ext.buildToolsVersion
defaultConfig {
applicationId "com.bakbakapp.bakbak"
minSdkVersion rootProject.ext.minSdkVersion
targetSdkVersion rootProject.ext.targetSdkVersion
versionCode 3
versionName "3.0"
}
signingConfigs {
release {
if (project.hasProperty('MYAPP_RELEASE_STORE_FILE')) {
storeFile file(MYAPP_RELEASE_STORE_FILE)
storePassword MYAPP_RELEASE_STORE_PASSWORD
keyAlias MYAPP_RELEASE_KEY_ALIAS
keyPassword MYAPP_RELEASE_KEY_PASSWORD
}
}
}
splits {
abi {
def isReleaseBuild = false
gradle.startParameter.taskNames.find {
if (it ==~ /:app:assemble.*Release/) {
isReleaseBuild = true
return true // break
}
return false // continue
}
reset()
enable enableSeparateBuildPerCPUArchitecture
universalApk true // If true, also generate a universal APK
include "x86", "x86_64", "armeabi-v7a", "arm64-v8a"
}
}
buildTypes {
release {
minifyEnabled enableProguardInReleaseBuilds
shrinkResources true
proguardFiles getDefaultProguardFile("proguard-android.txt"), "proguard-rules.pro"
signingConfig signingConfigs.release
}
}
// Map for the version code that gives each ABI a value.
def abiCodes = ['x86':1, 'x86_64':2, 'armeabi-v7a':3, 'arm64-v8a':4]
// applicationVariants are e.g. debug, release
applicationVariants.all { variant ->
variant.outputs.each { output ->
def abi = output.getFilter(OutputFile.ABI)
if (abi != null) {
output.versionCodeOverride = abiCodes.get(abi, 0) * 1048576 + defaultConfig.versionCode
}
}
}
}
As RN as of now only supports 32 bit applications, you will either need to use latest RN version 0.58.3 as
I have successfully used it and test it for 64 bit apps or alternatively you can remove the 64 builds of the app and then playstore will automatically install the 32 bit versions of the app for the users.
For only 32-bit support replace your
include "x86", "x86_64", "armeabi-v7a", "arm64-v8a"
with
include "x86" "armeabi-v7a"
and similarly
def abiCodes = ['x86':1, 'x86_64':2, 'armeabi-v7a':3, 'arm64-v8a':4]
with
def abiCodes = ['x86':1, 'armeabi-v7a':2]
You can track the RN 64 bit issue here
I Want generated build apk but after cd android && ./gradlew assembleRelease build failed.
there my info:
* What went wrong:
Could not list contents of '/Users/sweet/Desktop/phase/ka-
mobile/node_modules/react-native/third-party/glog-0.3.4/test-driver'.
Couldn't follow symbolic link.
i already put my-release-key.keystore under android/app
and change android/app/build.gradle
android {
compileSdkVersion 23
buildToolsVersion "23.0.1"
defaultConfig {
applicationId "com.kickavenue"
minSdkVersion 16
targetSdkVersion 22
versionCode 1
versionName "1.0"
ndk {
abiFilters "armeabi-v7a", "x86"
}
}
signingConfigs {
release {
if (project.hasProperty('MYAPP_RELEASE_STORE_FILE')) {
storeFile file(MYAPP_RELEASE_STORE_FILE)
storePassword MYAPP_RELEASE_STORE_PASSWORD
keyAlias MYAPP_RELEASE_KEY_ALIAS
keyPassword MYAPP_RELEASE_KEY_PASSWORD
}
}
}
splits {
abi {
reset()
enable enableSeparateBuildPerCPUArchitecture
universalApk false // If true, also generate a universal APK
include "armeabi-v7a", "x86"
}
}
buildTypes {
release {
minifyEnabled enableProguardInReleaseBuilds
proguardFiles getDefaultProguardFile("proguard-android.txt"), "proguard-rules.pro"
signingConfig signingConfigs.release
}
}
and change android/gradle.properties or change on ~/.gradle/gradle.properties
android.useDeprecatedNdk=true //only on android/gradle.properties i write
MYAPP_RELEASE_STORE_FILE=my-release-key.keystore
MYAPP_RELEASE_KEY_ALIAS=my-key-alias
MYAPP_RELEASE_STORE_PASSWORD=sample
MYAPP_RELEASE_KEY_PASSWORD=sample
there is wrong my step to build genereated APK
What version of RN are you using? This issue appears on RN 0.46.3 as stated on React Native's github: https://github.com/facebook/react-native/issues/14464
You could upgrade to React Native 0.47.0 to fix the issue.
Try deleting the .bin folder inside your node_modules