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
Related
I am using Android R8 obfuscation in my Android library.
After including the AAR file in the application module of the library's client project, I am getting compile time errors for interfaces that are declared inside the class or another interface.
e.g. one of the public interfaces is MyPublicInterface:
interface InterfaceA {
fun a()
}
interface InterfaceB {
fun b()
}
class ClassA {
interface NestedInterfaceOfA {
fun nia()
}
}
interface MyPublicInterface : InterfaceA, InterfaceB, ClassA.NestedInterfaceOfA
The interface MyPublicInterface is used by the application module.
I am getting the below errors while compiling the application module:
"Cannot access ClassA$NestedInterfaceOfA which is a supertype of MyPublicInterface. Please make sure you have the required dependencies in the classpath."
"unresolved supertypes ClassA$NestedInterfaceOfA"
I tried all the below rules:
-keepclasseswithmembers public interface * {
*;
}
-keepclasseswithmembernames public interface * {
*;
}
-keep public interface *$* {
*;
}
-keepclasseswithmembers public interface *$* {
*;
}
-keepclasseswithmembernames public interface *$* {
*;
}
-keepattributes InnerClasses, Signature
I tried by explicitly adding #Keep annotation in code and by explicitly adding the keep rule for a particular interface as well. But it didn't work.
Note: The entire code of the library is in Kotlin.
The above specified issue is resolved now.
I used below solution for it:
Android studio version: 4.1.x
Android tools version:
classpath 'com.android.tools.build:gradle:4.1.1' (Issue was occurring with version 4.0.2)
Gradle version: 6.5.1 (Issue was occurring with version 6.3)
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
After applying ProGuard on my production app. We are facing the following error on loading images from URLs
E/vw: Glide failed to load image with exception: UNABLE TO LOAD PUBLICSUFFIXES.GZ RESOURCE FROM THE CLASSPATH.
java.lang.IllegalStateException: Unable to load publicsuffixes.gz resource from the classpath.
Finally, we tried keeping the whole Glide sources in the progaurd configuration with the following command
-keep public class * implements com.bumptech.glide.module.GlideModule
-keep public enum com.bumptech.glide.load.resource.bitmap.ImageHeaderParser$** {
**[] $VALUES;
public *;
}
-keep class com.bumptech.glide.** {*;}
But still facing the same issue.
Not sure what exactly should be done to fix the error above.
We also tried keeping the exact path as mentioned in the error by doing the following:
-keep class okhttp3.internal.publicsuffix.PublicSuffixDatabase
-keepnames class okhttp3.internal.publicsuffix.PublicSuffixDatabase
I did try various recommended solutions on the Github issues and other forums but none of them helped.
use this in your app gradle file and it will solve the problem.
android {
defaultConfig {
multiDexEnabled true
}
packagingOptions {
pickFirst 'META-INF/*'
exclude "okhttp3/internal/publicsuffix/publicsuffixes.gz"
}
}
My android app uses Pushy.me Push notification service, i have built the signed apk with minifyEnabled true and when i run the app i am getting below error
org.apache.commons.logging.LogConfigurationException: The chosen LogFactory implementation does not extend LogFactory. Please check your configuration. (Caused by 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.b'.
i have added below lines in proguard-rules.pro file, but it shows same error
-dontwarn me.pushy.**
-keep class me.pushy.** { *; }
-dontwarn org.apache.commons.logging.**
This worked for me
-keep class org.apache.** { *; }
Link to project - File manager
After i'm enabling obfuscation, application crash, when i try to show fragment from library project that use data binding.
Error:
java.lang.NoClassDefFoundError: Failed resolution of: Lcorp/wmsoft/android/lib/filemanager/databinding/WmFmFileManagerViewLayoutBinding;
at corp.wmsoft.android.lib.filemanager.ui.widgets.nav.a.onCreateView(Unknown Source)
But Android Studio->Build->Analyze APK, show that i have this class inside APK:
library project proguard-rules.pro:
-dontwarn android.databinding.**
-keep class android.databinding.** { *; }
-keep class corp.wmsoft.android.lib.filemanager.databinding.** { *; }
Please help to solve this problem.