When invoking FirebaseFunctions.getInstance(FirebaseApp.getInstance()) an NPE is thrown. FirebaseApp.initializeApp(this); is called inside extended App class onCreate before calling any other firebase functionality.
This is the stacktrace:
Fatal Exception: java.lang.NullPointerException
at com.google.firebase.functions.internal.Preconditions.checkNotNull(Unknown Source:876)
at com.google.firebase.functions.FirebaseFunctions.<init>(Unknown Source:77)
at com.google.firebase.functions.FirebaseFunctions.getInstance(Unknown Source:141)
at com.google.firebase.functions.FirebaseFunctions.getInstance(Unknown Source:159)
The exception is thrown only when building the application with release configuration, this means the code gets obfuscated with DexGuard but all firebase classes have been excluded from the obfuscation, below my dexguard config:
...
-keep class com.google.** { *; }
-keep class android.** { *; }
-keep class com.firebase.** { *; }
-keep class com.android.** { *; }
...
I'm using:
com.google.firebase:firebase-functions:12.0.1 (also all other firebase libraries use the same version)
DexGuard version 8.1.15
classpath 'com.google.gms:google-services:4.0.1'
When using debug configuration everything works like charm, any idea how to solve this?
Already checked this similar question but it's outdated: Error with Firebase callable functions
EDIT - New configuration
I tried updating both DexGuard dependency and Firebase one with the ones below:
com.google.firebase:firebase-functions:16.1.1 (all other firebase and gms dependencies are updated to the latest one, except for play-services-ads that is 16.0.0)
DexGuard version 8.2.20
classpath 'com.google.gms:google-services:4.0.1'
This is the new stacktrace:
Fatal Exception: java.lang.NullPointerException: null reference
at com.google.firebase.functions.a.a.a(Unknown Source:30)
at com.google.firebase.functions.FirebaseFunctions.(Unknown Source:77)
at com.google.firebase.functions.FirebaseFunctions.getInstance(Unknown Source:141)
at com.google.firebase.functions.FirebaseFunctions.getInstance(Unknown Source:154)
For the ones who may face the same problem, it was caused by the "projectId" field being null when the FirebaseOptions were initialised by the sdk using FirebaseOptions.fromResource(Context) and the app was protected with DexGuard
FirebaseOptions {
applicationId = ***********************,
apiKeyapiKey = ***********************,
databaseUrl = ***********************,
gcmSenderId = ***********************,
storageBucket = ***********************,
projectId = null
}
The problem has been solved by adding the following line to the DexGuard config file:
-keepresources string/project_id
Related
i get this message error when i build my app in release mode.
No pending exception expected: java.lang.NoSuchFieldError: no "Ljava/lang/String;" field "amplitudes" in class "Llinc/com/amplituda/AmplitudaResultJNI;" or its superclasses.
But app correctly works on Dev build. What should i do?
gradle file
implementation 'com.github.lincollincol:amplituda:2.1.2'
proguard-rules.pro
-keep class linc.com.amplituda.** { *; }
Thanks
I have enabled Proguard and configured the rules
minifyEnabled true
shrinkResources true
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
For GSON I used these rules
added my models to exceptions (-keep class my.package.model.** { *; })
Also used other rules for various libraries
I have this error -> Registering an InstanceCreator with Gson for this type may fix this problem.
the error occurred when switching to kotlin 1.6.0 and 1.6.10.
There is no error on version Kotlin 1.5.21!
Error (I have a bug only on Kotlin 1.6.0/1.6.10. There is no error on kotlin 1.5.21) --->
E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.project.main, PID: 2943
java.lang.RuntimeException: Unable to invoke no-args constructor for class com.project.main.domain.entity.MyEntityClass. Registering an InstanceCreator with Gson for this type may fix this problem.
at com.google.gson.internal.c$e.a(SourceFile:228)
at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory$Adapter.read(SourceFile:212)
at com.google.gson.Gson.h(SourceFile:963)
at com.google.gson.Gson.j(SourceFile:928)
at com.google.gson.Gson.l(SourceFile:877)
at com.project.main.data.cache.converter.MyEntityClassConverter.toMyEntityClass(SourceFile:14)
at com.project.main.data.cache.dao.MyProjectDao_Impl$21.call(SourceFile:947)
at com.project.main.data.cache.dao.MyProjectDao_Impl$21.call(SourceFile:889)
at k1.c$a$a$a$a.invokeSuspend(SourceFile:128)
at uh.a.resumeWith(SourceFile:33)
at uk.z0.run(SourceFile:106)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641)
at java.lang.Thread.run(Thread.java:923)
Caused by: java.lang.UnsupportedOperationException: Abstract class can't be instantiated! Class name: com.project.main.domain.entity.MyEntityClass
at com.google.gson.internal.l.a(SourceFile:120)
at com.google.gson.internal.l$a.c(SourceFile:49)
at com.google.gson.internal.c$e.a(SourceFile:225)
at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory$Adapter.read(SourceFile:212)
at com.google.gson.Gson.h(SourceFile:963)
at com.google.gson.Gson.j(SourceFile:928)
at com.google.gson.Gson.l(SourceFile:877)
at com.project.main.data.cache.converter.MyEntityClassConverter.toMyEntityClass(SourceFile:14)
at com.project.main.data.cache.dao.MyProjectDao_Impl$21.call(SourceFile:947)
at com.project.main.data.cache.dao.MyProjectDao_Impl$21.call(SourceFile:889)
at k1.c$a$a$a$a.invokeSuspend(SourceFile:128)
at uh.a.resumeWith(SourceFile:33)
at uk.z0.run(SourceFile:106)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641)
at java.lang.Thread.run(Thread.java:923)
I have rules for this error.
-keep class com.project.main.domain.entity.MyEntityClass { ; }
but I'm adding the whole package
-keep class com.project.main.domain.entity.* { *; }
I also have all the other rules for GSON -> rules
#TypeConverter
fun toMyEntityClass(value: String): MyEntityClass =
gson.fromJson(value, object : TypeToken<MyEntityClass>() {}.type) //Error
I also tried to prescribe just one rule. The rule helps to run the project on 1.5.21 and works. But it doesn't work on 1.6.0 - 1.6.10. I don't want to create an Instance Creator. I have too many models and I will waste a lot of time.
-keep class ** { *; }
For any classes that interact with GSON you have to keep as follow :
-keep class "MODEL CLASSES"
for your issue you can do like :
-keep class com.project.main.domain.entity.** { *; }
It will keep all classes under the entity package.
The problem was solved by itself, after updating the libraries
gson 2.9.0
and kotlin 2.6.21
I didn't do anything, just updated to these versions
I haven't checked 1.6.0 and 1.6.10 works in tandem with gson 2.9.0 but gson didn't work with the previous release version
As a result, I upgraded Kotlin from 1.5.21 -> 1.6.21
I'm trying to integrate TWILIO in my app using
implementation group: "com.twilio.sdk", name: "twilio", version: "8.7.0"
but am getting the following error
More than one file was found with OS independent path 'META-INF/DEPENDENCIES'.
Then after searching this error I found that it can be resolved by adding
packagingOptions {
exclude 'META-INF/DEPENDENCIES'
}
After adding the app now built successfully. After running the app I got the following error
Caused by: j.a.a.b.b: java.lang.ClassCastException: The application has specified that a custom LogFactory implementation should be used but Class 'org.apache.commons.logging.impl.LogFactoryImpl' cannot be converted to 'org.apache.commons.logging.LogFactory'. Please check the custom implementation
then to solve this error I added
-keep class org.apache.** { *; }
to the proguard-rules file
After running the code again I get the following error
java.lang.NoSuchFieldError: No static field INSTANCE of type Lorg/apache/http/conn/ssl/AllowAllHostnameVerifier;
in class Lorg/apache/http/conn/ssl/AllowAllHostnameVerifier;
or its superclasses (declaration of 'org.apache.http.conn.ssl.AllowAllHostnameVerifier' appears in /system/framework/framework.jar!classes3.dex)
To which I'm not able to find a solution. Could someone please help me resolve these error to add TWILIO to my project?
Edit - 1
After adding print in the code I found out the line of code cause the above error is
Token token = Token.creator().create();
I'm trying to implement the following code
import com.twilio.Twilio;
import com.twilio.rest.api.v2010.account.Token;
public class Example {
// Find your Account Sid and Token at twilio.com/console
// and set the environment variables. See http://twil.io/secure
public static final String ACCOUNT_SID = System.getenv("TWILIO_ACCOUNT_SID");
public static final String AUTH_TOKEN = System.getenv("TWILIO_AUTH_TOKEN");
public static void main(String[] args) {
Twilio.init(ACCOUNT_SID, AUTH_TOKEN);
Token token = Token.creator().create();
System.out.println(token.getUsername());
}
}
from
https://www.twilio.com/docs/stun-turn
Voice Android 3.2.0+
# Twilio Programmable Voice
-keep class com.twilio.** { *; }
-keep class tvo.webrtc.** { *; }
-dontwarn tvo.webrtc.**
-keep class com.twilio.voice.** { *; }
-keepattributes InnerClasses
These rules ensure that the Programmable Voice library is not removed by ProGuard.
https://www.twilio.com/docs/voice/voip-sdk/android
I'm facing a crash after setting minifyEnabled true in my app/build.gradle.
implementation ('com.google.android.gms:play-services-location:17.0.0') {
exclude group:'com.android.support', module: 'support-v4'
}
implementation 'com.google.firebase:firebase-messaging:18.0.0'
implementation 'com.google.firebase:firebase-analytics:16.5.0'
implementation 'com.google.android.gms:play-services-maps:17.0.0'
These are the Firebase libraries i use. This crash only arises if set minifyEnabled true.
I've tried enabling Multidex too, still unable to resolve the issue.
Crash log:
Process: proto.inventa.cct.com.inventaapp, PID: 30410
java.lang.NoSuchMethodError: No static method checkHandlerThread(Landroid/os/Handler;Ljava/lang/String;)V in class Lcom/google/android/gms/common/internal/Preconditions; or its super classes (declaration of 'com.google.android.gms.common.internal.Preconditions' appears in /data/app/proto.inventa.cct.com.inventaapp-hunIIikgxzy10RXjTw7TYA==/base.apk!classes4.dex)
at com.google.android.gms.common.internal.GmsClientEventManager.onConnectionSuccess(Unknown Source:20)
at com.google.android.gms.common.api.internal.zaaw.zab(Unknown Source:292)
at com.google.android.gms.common.api.internal.zaak.zaaq(Unknown Source:125)
at com.google.android.gms.common.api.internal.zaak.onConnected(Unknown Source:105)
at com.google.android.gms.common.api.internal.zabe.onConnected(Unknown Source:101)
at com.google.android.gms.common.api.internal.zaq.onConnected(Unknown Source:6)
at com.google.android.gms.common.internal.zaf.onConnected(Unknown Source:2)
at com.google.android.gms.common.internal.BaseGmsClient$PostInitCallback.handleServiceSuccess(Unknown Source:130)
at com.google.android.gms.common.internal.BaseGmsClient$zza.deliverCallback(Unknown Source:60)
at com.google.android.gms.common.internal.BaseGmsClient$zza.deliverCallback(Unknown Source:2)
at com.google.android.gms.common.internal.BaseGmsClient$CallbackProxy.deliverCallback(Unknown Source:51)
at com.google.android.gms.common.internal.BaseGmsClient$zzb.handleMessage(Unknown Source:270)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:214)
at android.app.ActivityThread.main(ActivityThread.java:6977)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:528)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:910)
You'd need to keep these classes (there may be more):
-verbose
-keep,includedescriptorclasses class com.google.android.gms.** { *; }
-keep,includedescriptorclasses class com.google.android.gms.internal.** { *; }
-keep class com.google.android.gms.internal.** {com.google.android.gms.internal.** initialize(android.content.Context);}
-keep class com.google.android.gms.iid.** {com.google.android.gms.iid.** get(java.lang.String);}
-keep,includedescriptorclasses class com.google.android.** { *; }
You seem to have a dependency conflict.
play-services-location:17.0.0 depends on play-services-basement:17.0.0 and play-services-base:17.0.0
But
firebase-messaging:18.0.0 depends on play-services-basement:16.0.1
It may be that you have play-services-base:17.0.0 but play-services-basement:16.0.1, which won't work if play-services-base:17.0.0 is trying to use APIs introduced in play-services-basement:17.0.0.
Try updating your firebase-messaging dep to at least version 19.0.0, which does depend on play-services-basement:17.0.0.
Similarly, try updating firebase-analytics to at least version 17.0.0
Also consider checking out the strict version matcher plugin, which will give you an error message if a conflict is detected instead of Gradle's default strategy which just chooses one and if it makes the wrong choice may give odd error messages like this.
https://developers.google.com/android/guides/versioning#strict_version_matching.
Also I highly encourage against -keeping all of the com.google.android packages. That will keep all the code in the SDK, even the parts you don't use, drastically reducing how much benefit shrinking will give.
I'm Using FCM with Dexguard.
FCM cannot make token in release build.
but, it works well in debug build.
my gradle settings
classpath 'com.google.gms:google-services:3.2.1'
compile 'com.google.android.gms:play-services-base:15.0.2'
compile 'com.google.android.gms:play-services-analytics:15.0.2'
compile 'com.google.firebase:firebase-core:15.0.2'
compile 'com.google.firebase:firebase-messaging:15.0.2'
And, ShrinkResources = false And optimize 5time by Dexguard
gradle version : 4.1
android gradle plugin : 2.3.3
options in dexguardFile related with FCM
-keep public class com.google.firebase.** { *; }
-keep public class com.google.firebase.iid.FirebaseInstanceId { public *;}
Firebase 15+ requires some additional rules. The latest DexGuard version 8.2.09 for example includes all necessary configurations.
Add the following dexguard rules to fix the problem:
-keep class com.google.firebase** { *; }
-dontshrink
It seems that dexguard removes all classes that are not directly referenced in code. So the entry points like services classes to get firebase tokens (FirebaseInstanceIdService) will be removed during obfuscation process, if shrinking is allowed.
I had similar issues with Firebase analytics where it works for debug build but not the release build, thanks to T. Neidhart's answer above I found this block from the Dexguard 8.4.13 sample - samples/advanced/GooglePlayServices/AdMob/dexguard-project.txt and it solves the problem for me.
-keep public class !**.internal.**, com.google.** {
public protected *;
}
# We can repackage all obfuscated classes in a new internal package.
-repackageclasses com.google.internal