Rezo Shalikashvili
Rezo Shalikashvili

Reputation: 89

R8: NullPointerException during IR Conversion

I have a problem when trying to generate a release version of my app. It gives a strange error

C:\Users\rshal\.gradle\caches\transforms-2\files-2.1\6c326691eb00442622017dd95f96e92a\jetified-firebase-config-19.1.3-runtime.jar: R8: NullPointerException during IR Conversion
> Task :app:minifyProdReleaseWithR8 FAILED

I have been using firebase analytics and firebase remote config without problems. And also I had no issue this R8 minimization. Recently I have integrated google-speech-api and after that, I am not able to use R8.

I did not have this problem until I integrated google-speech-api in the app. I know that google-speech-api is not officially supported on Android. Maybe that is the core issue. Before that, I had an issue with firebase-config dependency. It is not compatible with the google-speech-api library I think. I solved that issue with this Gradle configuration

implementation('com.google.firebase:firebase-config', {
    exclude group: 'com.google.protobuf' // google-cloud-speech causes this. see  https://github.com/firebase/firebase-android-sdk/issues/1143
})

I have followed this fix.

Now I am stuck with this error that I showed above.

I have tried different versions on R8 as suggested here

This is gradle build log

> Task :app:minifyProdReleaseWithR8
R8: Missing class: org.apache.logging.log4j.spi.ExtendedLoggerWrapper
R8: Missing class: org.eclipse.jetty.npn.NextProtoNego$ClientProvider
R8: Missing class: javax.servlet.ServletContextListener
R8: Missing class: org.jboss.marshalling.ByteOutput
R8: Missing class: java.lang.ClassValue
R8: Missing class: org.eclipse.jetty.alpn.ALPN$ClientProvider
R8: Missing class: org.jboss.marshalling.ByteInput
R8: Missing class: org.eclipse.jetty.alpn.ALPN$ServerProvider
R8: Missing class: org.eclipse.jetty.npn.NextProtoNego$ServerProvider
R8: Library class android.net.http.AndroidHttpClientConnection implements program class org.apache.http.HttpInetConnection
R8: Library class android.net.http.AndroidHttpClientConnection implements program class org.apache.http.HttpConnection
C:\Users\rshal\.gradle\caches\transforms-2\files-2.1\6c326691eb00442622017dd95f96e92a\jetified-firebase-config-19.1.3-runtime.jar: R8: NullPointerException during IR Conversion

> Task :app:minifyProdReleaseWithR8 FAILED

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':app:minifyProdReleaseWithR8'.
> com.android.tools.r8.CompilationFailedException: Compilation failed to complet

this is build.gradle file

this is top-level Gradle file

Upvotes: 4

Views: 1821

Answers (1)

Rezo Shalikashvili
Rezo Shalikashvili

Reputation: 89

Answering my own question because it turned out to be an R8 bug and after me reporting it, they solved the issue. Which is great.

Full bug report and how to apply fix is here

Short version:

change gradle configuration to this

buildscript {
repositories {
    maven {
        url 'https://storage.googleapis.com/r8-releases/raw'
    }
}
    dependencies {
        classpath 'com.android.tools:r8:1.6.88'          // Must be before the Gradle Plugin for Android.
        classpath 'com.android.tools.build:gradle:3.6.2'
     }
}

I have encountered this bug when implementing Google Speech API in my android app. For anyone who might need it, this is my final groguard configuration

-keep class com.google.api.gax.** {*;}
-keep class com.google.cloud.** {*;}
-keep class com.google.api.services.translate.** {*;}
-keep class com.google.api.client.util.** {*;}
-keep class com.google.api.client.googleapis.** {*;}
-keep class com.google.cloud.speech.v1.stub.** {*;}
-keep class io.grpc.** {*;}
-keep class com.google.auth.oauth2.** {*;}
-keep class com.google.auth.** {*;}

Upvotes: 2

Related Questions