Error generating signed apk with android map utils library - android

Since I added this dependency I cannot generate a signed APK anymore. Weirdly, Build/Build APK works, but Build/Generate signed APK fails with these lines:
Warning:com.google.maps.android.clustering.ClusterManager: can't find superclass or interface com.google.android.gms.maps.GoogleMap$OnCameraIdleListener
Warning:com.google.maps.android.clustering.ClusterManager: can't find referenced class com.google.android.gms.maps.GoogleMap$OnCameraIdleListener
Warning:com.google.maps.android.kml.KmlRenderer: can't find referenced method 'void setZIndex(float)' in program class com.google.android.gms.maps.model.Marker
Warning:there were 4 unresolved references to classes or interfaces.
Warning:there were 1 unresolved references to program class members.
Warning:Exception while processing task java.io.IOException: Please correct the above warnings first.
Error:java.lang.RuntimeException: java.io.IOException: Please correct the above warnings first.
Error:java.io.IOException: Please correct the above warnings first.
Information:BUILD FAILED
Here is my module build.gradle dependency part:
apply plugin: 'com.android.model.library'
apply plugin: 'com.google.gms.google-services'
dependencies {
compile 'com.google.android.gms:play-services-maps:9.0.2'
compile 'com.google.maps.android:android-maps-utils:0.4+'
}
model
{
[etc...]
}
And this is the project level one:
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle-experimental:0.8.0'
classpath 'com.google.gms:google-services:3.0.0'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}

it may be Proguard (which is doing its work) when you try to generate the signed apk(release version), you may solve this by adding
-keep public class com.google.android.gms.* { public *; }
-dontwarn com.google.android.gms.**
But normally this is already done in the maps library, i would recommend using the latest version the maps lib before You try the above solution
com.google.android.gms:play-services-maps:9.8.0

Related

com.android.tools.r8.CompilationFailedException:Compilation failed to complete, position:Lcom/facebook/login/DefaultAudience$EnumUnboxingLocalUtility;

I have some error, after updated kotlin version (ext.kotlin_version) to 1.6.10:
com.android.tools.r8.internal.E00: Unexpected type in conversion to primitive: OBJECT
Execution failed for task ':app:minifyReleaseWithR8'.
> com.android.tools.r8.CompilationFailedException: Compilation failed to complete, position: Lcom/facebook/login/DefaultAudience$EnumUnboxingLocalUtility;getNativeProtocolAudience(I)Ljava/lang/String;, origin: ..\.gradle\caches\transforms-3\57102c4e3d32396b86898e5ca0dd620d\transformed\jetified-facebook-core-7.1.0-runtime.jar:com/facebook/login/DefaultAudience.class
It happened, if I use options minifyEnabled true in my build.gradle(:app) with Generate signed bundle.
If I use old ext.kotlin_version (for examle, 1.5.0) this error did not appear.
I think, if I use correct rule(s) in proguard-rules.pro I could resolve this issue.
This was caused by an issue in R8. Fix is available in R8 3.1.71, 3.2.55 and 3.3.26-dev versions.
Add the following to settings.gradle or settings.gradle.kts to use a specific version of R8 different from the one bundeled with AGP:
pluginManagement {
buildscript {
repositories {
mavenCentral()
maven {
url = uri("https://storage.googleapis.com/r8-releases/raw")
}
}
dependencies {
classpath("com.android.tools:r8:X.Y.Z")
classpath('com.google.guava:guava:30.1.1-jre') // <-- THIS IS REQUIRED UNTIL R8 3.2.4-dev
}
}
}
I find right rule for decide this problem.
You need add this code into proguard-rules.pro:
-keep class com.facebook.login.** {*;}
This line let ignore option minifyEnabled true for all files into com.facebook.login package.

R8 Crashes Silently on Build

I get the following warning - error when building an Android release.
WARNING:R8: Unexpected error during rewriting of Kotlin metadata for class 'androidx.lifecycle.LifecycleController$observer$1':
com.android.tools.r8.internal.sG: lateinit property function has not been initialized
at com.android.tools.r8.internal.Xn.a(SourceFile:302)
at com.android.tools.r8.internal.Kn.a(SourceFile:49)
at com.android.tools.r8.internal.Kn.a(SourceFile:24)
at com.android.tools.r8.utils.V.a(SourceFile:36)
at com.android.tools.r8.utils.V.a(SourceFile:41)
at com.android.tools.r8.utils.V.a(SourceFile:35)
at java.base/java.util.concurrent.ForkJoinTask$AdaptedCallable.exec(ForkJoinTask.java:1448)
at java.base/java.util.concurrent.ForkJoinTask.doExec(ForkJoinTask.java:290)
at java.base/java.util.concurrent.ForkJoinPool$WorkQueue.topLevelExec(ForkJoinPool.java:1020)
at java.base/java.util.concurrent.ForkJoinPool.scan(ForkJoinPool.java:1656)
at java.base/java.util.concurrent.ForkJoinPool.runWorker(ForkJoinPool.java:1594)
at java.base/java.util.concurrent.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:183)
Usually I wouldn't have given much attention to a warning.
But we're experiencing a related lifecycle bug in release (like the observer doesn't work at all).
I've tried -keepclasseswithmembers class androidx.lifecycle.LifecycleController.** { *; } with no luck.
Applying the R8 plugin in my Project lvl gradle fix this issue for me:
buildscript {
repositories {
maven {
url 'https://storage.googleapis.com/r8-releases/raw'
}
}
dependencies {
classpath 'com.android.tools:r8:3.0.65' // Must be before the Gradle Plugin for Android.
classpath 'com.android.tools.build:gradle:X.Y.Z' // Your current AGP version.
}
}

VerifyError: Verifier rejected class ... 'this' arg must be initialized

after third-party library upgrade I got a new crash on app launch:
java.lang.VerifyError: Verifier rejected class ly.img.android.e: void ly.img.android.e.<init>(java.lang.String, boolean) failed to verify: void ly.img.android.e.<init>(java.lang.String, boolean): [0x5C] 'this' arg must be initialized (declaration of 'ly.img.android.e' appears in base.apk!classes2.dex)
at ly.img.android.b.<clinit>(Unknown Source:46)
at ly.img.android.c.b(Unknown Source:0)
at ly.img.android.PESDK.initSDK(Unknown Source:0)
at ly.img.android.IMGLYAutoInit.onCreate(IMGLYAutoInit.java:41)
at android.content.ContentProvider.attachInfo(ContentProvider.java:2092)
at android.content.ContentProvider.attachInfo(ContentProvider.java:2066)
at android.app.ActivityThread.installProvider(ActivityThread.java:6983)
at android.app.ActivityThread.installContentProviders(ActivityThread.java:6528)
Yes, I know that there are a lot of similar problems there but I didn't find any solution or advise for me.
So, maybe someone there can provide hint or advise for me what's wrong there. Thanks
Others were also facing this kind of issue, I think this can help you! ⛅
java.lang.VerifyError: Verifier rejected class ly.img.android.e: void ly.img.android.e.<init>(java.lang.String, boolean) failed to verify: void ly.img.android.e.<init>(java.lang.String, boolean): [0x5C] 'this' arg must be initialized (declaration of 'ly.img.android.e' appears in base.apk!classes2.dex)
But according to a GitHub thread they found a solution to this problem
https://github.com/CleverTap/clevertap-android-sdk/issues/15#issuecomment-454842450
The fix for this issue is available for AGP(Android Gradle Plugin) 3.3 (and 3.4) by setting an explicit dependency detailed below.
After AGP 3.3.1 is released, remove the pinned version to allow you to pick up new D8/R8 releases again.
For AGP 3.3 amend your top-level build.gradle file with:
buildscript {
repositories {
maven {
url "http://storage.googleapis.com/r8-releases/raw" // ADD THIS.
}
}
dependencies {
classpath 'com.android.tools:r8:1.3.52' // ADD THIS. Must be before the Gradle Plugin for Android.
classpath 'com.android.tools.build:gradle:3.3'
}
}
For AGP 3.4 the r8 version should be 1.4.25
I have a suggestion
Maybe it will help
android {
defaultConfig {
...
// Enabling multidex support.
multiDexEnabled true
}
...
}
and
implementation 'com.android.support:multidex:1.0.0'
How did I resolve the issue:
I have upgraded gradle version from 3.5.3 to 3.6.3. Ough and thank you. Maybe my experience can help somebody.
I think this is the probelm with third-party library.
In my case, I built the library .jar myself and had no idea why the VerifyError would appear when trying to test the .jar in a test application.
The problem was in proguard.cfg with -assumenosideeffects and Log.
Specifically, inside proguard.cfg (of my library) there was a following line:
-assumenosideeffects class android.util.Log {*;}
Replacing it with:
-assumenosideeffects class android.util.Log {
public static *** v(...);
public static *** d(...);
public static *** i(...);
public static *** w(...);
public static *** e(...);
}
and building and obfuscating it again resolved the problem.
I found the answer to my problem here.
I know this doesn't directly answer to the original question, but I left this answer here in order to help someone who is trying to build the .jar and the result of using it is VerifyError.
I had a similar error:
FATAL EXCEPTION: Connection#7864356
Process: ..., PID: 24458
java.lang.VerifyError: Verifier rejected class r8.a: r8.b r8.a.b(w8.a[]) failed to verify: r8.b r8.a.b(w8.a[]): [0x33] expected to be within a catch-all for an instruction where a monitor is held (declaration of 'r8.a' appears in /data/app/~~DIy9qxh1lGM...==/base.apk)
at p7.g$b.b(SourceFile:270)
at p7.g$b.run(SourceFile:35)
This happened after I updated gradle from 4.2.2 to 7.3.1. I tried disabling obfuscation and the #Keep option for the specified classes in the error message. But nothing helped. In debug mode, everything still worked, but in the release the app crashed with an error.
Thanks Dupinder Singh.
I've changed my top-level build.gradle file with:
buildscript {
repositories {
google()
mavenCentral()
}
dependencies {
classpath 'com.android.tools:r8:4.0.48'
classpath 'com.android.tools.build:gradle:7.3.1'
}
}
allprojects {
repositories {
google()
mavenCentral()
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
Now everything works. Maybe my solution will help someone.

Unable to sign release APK - :app:shrinkReleaseMultiDexComponents FAILED

I'm trying to generate a signed apk and the log keeps showing me the following error:
:app:compileReleaseJavaWithJavac
Note: Some input files use or override a deprecated API.
Note: Recompile with -Xlint:deprecation for details.
:app:compileReleaseNdk UP-TO-DATE
:app:compileReleaseSources
:app:collectReleaseMultiDexComponents
:app:proguardRelease
Warning:com.google.android.gms.internal.zzac: can't find referenced class android.net.http.AndroidHttpClient
Warning:com.google.android.gms.internal.zzw: can't find referenced method 'void addHeader(java.lang.String,java.lang.String)' in program class com.google.android.gms.internal.zzw$zza
Warning:com.google.android.gms.internal.zzw$zza: can't find referenced method 'void setURI(java.net.URI)' in program class com.google.android.gms.internal.zzw$zza
Warning:com.ironsource.mobilcore.j: can't find referenced method 'void setLatestEventInfo(android.content.Context,java.lang.CharSequence,java.lang.CharSequence,android.app.PendingIntent)' in library class android.app.Notification
Warning:com.mopub.volley.toolbox.HttpClientStack: can't find referenced method 'void addHeader(java.lang.String,java.lang.String)' in program class com.mopub.volley.toolbox.HttpClientStack$HttpPatch
Warning:com.mopub.volley.toolbox.HttpClientStack$HttpPatch: can't find referenced method 'void setURI(java.net.URI)' in program class com.mopub.volley.toolbox.HttpClientStack$HttpPatch
Warning:com.mopub.volley.toolbox.Volley: can't find referenced class android.net.http.AndroidHttpClient
Warning:there were 4 unresolved references to classes or interfaces.
You may need to add missing library jars or update their versions.
If your code works fine without the missing classes, you can suppress
the warnings with '-dontwarn' options.
(http://proguard.sourceforge.net/manual/troubleshooting.html#unresolvedclass)
Warning:there were 4 unresolved references to program class members.
Your input classes appear to be inconsistent.
You may need to recompile the code.
(http://proguard.sourceforge.net/manual/troubleshooting.html#unresolvedprogramclassmember)
Warning:there were 1 unresolved references to library class members.
You probably need to update the library versions.
(http://proguard.sourceforge.net/manual/troubleshooting.html#unresolvedlibraryclassmember)
Exception while processing task
java.io.IOException: Please correct the above warnings first.
at proguard.Initializer.execute(Initializer.java:473)
at proguard.ProGuard.initialize(ProGuard.java:233)
at proguard.ProGuard.execute(ProGuard.java:98)
at proguard.gradle.ProGuardTask.proguard(ProGuardTask.java:1074)
at com.android.build.gradle.tasks.AndroidProGuardTask.doMinification(AndroidProGuardTask.java:139)
at com.android.build.gradle.tasks.AndroidProGuardTask$1.run(AndroidProGuardTask.java:115)
at com.android.builder.tasks.Job.runTask(Job.java:48)
at com.android.build.gradle.tasks.SimpleWorkQueue$EmptyThreadContext.runTask(SimpleWorkQueue.java:41)
at com.android.builder.tasks.WorkQueue.run(WorkQueue.java:227)
at java.lang.Thread.run(Thread.java:745)
:app:shrinkReleaseMultiDexComponents FAILED
Error:Execution failed for task ':app:shrinkReleaseMultiDexComponents'.
> java.io.IOException: The output jar [<project_path>\app\build\intermediates\multi-dex\release\componentClasses.jar] must be specified after an input jar, or it will be empty.
Below is my app-level build.gradle:
apply plugin: 'com.android.application'
android {
compileSdkVersion 23
buildToolsVersion "23.0.1"
defaultConfig {
applicationId "com.my.app"
minSdkVersion 14
targetSdkVersion 23
versionCode 25
versionName "2.5"
// Enabling multidex support.
multiDexEnabled true
}
buildTypes {
release {
minifyEnabled true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
dexOptions {
incremental true
javaMaxHeapSize "2048M"
}
}
repositories {
mavenCentral()
maven { url "https://jitpack.io" }
}
dependencies {
compile 'com.android.support:multidex:1.0.1'
compile 'com.android.support:appcompat-v7:23.0.1'
compile 'com.android.support:design:23.0.1'
compile 'com.android.support:recyclerview-v7:23.0.1'
compile 'com.google.android.gms:play-services:8.1.0'
compile 'com.google.code.gson:gson:2.3.1'
compile 'com.squareup.okhttp:okhttp:2.4.0'
compile 'com.facebook.android:facebook-android-sdk:4.2.0'
compile 'me.dm7.barcodescanner:zxing:1.7.2'
compile 'de.hdodenhof:circleimageview:1.3.0'
compile 'com.scottyab:secure-preferences-lib:0.1.3'
compile 'com.soundcloud.android:android-crop:1.0.0#aar'
compile('com.afollestad.material-dialogs:core:0.8.1.0#aar') {
transitive = true
}
compile('com.mopub:mopub-sdk:3.13.0#aar') {
transitive = true
}
compile project(':android-support-v4-preferencefragment')
compile project(':circular_progress_bar')
compile files('libs/mobilecore_V1.1.jar')
compile files('libs/libAdapterSDKMoPub.jar')
compile files('libs/adcolony.jar')
}
And my top-level build.gradle:
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:1.3.0'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
jcenter()
}
}
I have tried with other version of gradle like 1.4.0-beta1', 1.4.0-beta2, and 1.3.1 still no luck.
There is some info right there in your trace --
Warning:there were 4 unresolved references to classes or interfaces.
You may need to add missing library jars or update their versions.
If your code works fine without the missing classes, you can suppress
the warnings with '-dontwarn' options.
(http://proguard.sourceforge.net/manual/troubleshooting.html#unresolvedclass)
At least part of your problem is that AndroidHttpClient was removed in API 23, and at least one of your libraries depends on it. You have three options.
1) You can include the following in your build.gradle file. Which includes the legacy library in your apk. See Apache HTTP Client Removal.
android {
useLibrary 'org.apache.http.legacy'
}
2) You can lower your target and compile sdk to 22 instead of 23. That should allow you to compile, or at least resolve the AndroidHttpClient issue until the libraries are updated to not require it.
3) You can add -dontwarn commands to your proguard file to suppress the warns to get a build. As noted in the documentation, this can be dangerous if you aren't certain the warnings can be safely ignored. I am not certain if ignoring warnings stemming from the removal of HttpClient and associated classes is safe or not. It might lead to an unstable build when running on M, but should be safe for L and below because those classes exist on devices at that API level.
ADDED:
For whoever struggles the same, keep in mind that you'll have to lower your builToolsVersion and com.android.support in the dependency to 22.0.1.
this is a very easy problem to solve. the problem rises when you are developing an app and somewhere in the middle you update your SDK. this is fine but you what you don't know the gradle configuration for you project should be up to date. so simply create a new project and look at your classpath which for mine was com.android.tools.build:gradle:1.3.1 in the project but now new projects class path are classpath 'com.android.tools.build:gradle:1.5.0' . the other thing to consider is compileSdkVersion , buildToolsVersion , targetSdkVersion. you should also check if your libraries version are up to date. you can find their versions by simply opening you SDK-manager.
so to wrap it up:
this is what your project gradle should be updated:
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:1.5.0' //update this section to the lates gradle core available
}
}
and this is the sections in gradle module level file that should be updated:
android {
compileSdkVersion 23 // update this one
buildToolsVersion "23.0.2" // update this one
defaultConfig {
applicationId "ranjbar.hadi.something"
minSdkVersion 14
targetSdkVersion 23 // update this one
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled true
proguardFiles getDefaultProguardFile('proguard-android.txt'),
'proguard-rules.pro'
}
}
}
hope this helps

Using android Parceler library with minifyEnabled

Whenever I try to minify my project that makes use of the parceler library, I cannot build a release apk because of a lot of warnings from proguard. For example:
Warning:org.parceler.transfuse.gen.FilerResourceWriter: can't find referenced class javax.tools.FileObject
I don't even make use of most of the libraries reported in this messages. What I'd like to know is if someone has encountered this problem and managed to solve it.
I tried to use -dontwarn to suppress all messages, but it does not seems correct, and besides it makes my app crash in rare cases (which makes me thing that some of the warning messages are indeed correct, but I'd like the library to keep the needed classes automatically).
My gradle script is as follows:
apply plugin: 'com.android.application'
...
dependencies {
...
compile 'org.parceler:parceler:1.0.3'
}
You are seeing this error from Proguard because you've included Parceler as a runtime dependency. Parceler was designed to be included into your project as two separate libraries; the annotation processor and the api. If you're running Gradle your build script should look like the following:
compile "org.parceler:parceler-api:1.0.3"
apt "org.parceler:parceler:1.0.3"
See Getting Parceler.
where apt is the android-apt plugin. Secondarily, it can also be run under the provided scope.
Your build script will look like the following in the end:
buildscript {
repositories {
mavenCentral()
}
dependencies {
// replace with the current version of the Android plugin
classpath 'com.android.tools.build:gradle:1.3.0'
// the latest version of the android-apt plugin
classpath 'com.neenbedankt.gradle.plugins:android-apt:1.7'
}
}
apply plugin: 'com.android.application'
apply plugin: 'com.neenbedankt.android-apt'
...
dependencies {
...
compile "org.parceler:parceler-api:1.0.3"
apt "org.parceler:parceler:1.0.3"
}

Categories

Resources