AppLovin / AppLovin-MAX-Flutter

MIT License
50 stars 29 forks source link

Issue with video playback and interstitial ad in release mode #93

Open OttomanDeveloper opened 1 year ago

OttomanDeveloper commented 1 year ago

MAX Plugin Version

2.5.0

Flutter Version

3.10.2

Device/Platform Info

Poco X3 Pro Android 13 and Also other devices.

Current Behavior

I encountered an issue where my app crashes when trying to load an ad while playing a video using the video_player package. The ads load successfully on other screens, but this issue occurs specifically when attempting to play a video and show the interstitial ad.

Interestingly, I don't encounter this issue in debug mode, only in release mode.

Packages used in my app:

Error Logs:

E/AndroidRuntime(30065): FATAL EXCEPTION: pool-16-thread-1
E/AndroidRuntime(30065): Process: com.videodownloader.udownload, PID: 30065
E/AndroidRuntime(30065): java.lang.NoClassDefFoundError: k9.w3
E/AndroidRuntime(30065):        at k9.n.o(Unknown Source:0)
E/AndroidRuntime(30065):        at ua.a.b(Unknown Source:40)
E/AndroidRuntime(30065):        at pa.y.c(Unknown Source:21)
E/AndroidRuntime(30065):        at pa.y.a(Unknown Source:35)
E/AndroidRuntime(30065):        at qa.e1.T0(Unknown Source:0)
E/AndroidRuntime(30065):        at qa.e1.c0(Unknown Source:106)
E/AndroidRuntime(30065):        at qa.e1.M0(Unknown Source:18)
E/AndroidRuntime(30065):        at qa.e1.Q(Unknown Source:0)
E/AndroidRuntime(30065):        at qa.u0.apply(Unknown Source:10)
E/AndroidRuntime(30065):        at j$.util.stream.d2.accept(SourceFile:0)
E/AndroidRuntime(30065):        at j$.util.stream.d2.accept(SourceFile:0)
E/AndroidRuntime(30065):        at j$.util.stream.d2.accept(SourceFile:0)
E/AndroidRuntime(30065):        at j$.util.a.forEachRemaining(SourceFile:0)
E/AndroidRuntime(30065):        at j$.util.stream.c.f0(SourceFile:0)
E/AndroidRuntime(30065):        at j$.util.stream.c.I0(Unknown Source:10)
E/AndroidRuntime(30065):        at j$.util.stream.U.y(SourceFile:0)
E/AndroidRuntime(30065):        at j$.util.stream.c.L0(SourceFile:0)
E/AndroidRuntime(30065):        at j$.util.stream.k2.forEach(SourceFile:0)
E/AndroidRuntime(30065):        at j$.util.stream.g2.accept(Unknown Source:24)
E/AndroidRuntime(30065):        at j$.util.Y.forEachRemaining(Unknown Source:20)
E/AndroidRuntime(30065):        at j$.util.stream.c.f0(SourceFile:0)
E/AndroidRuntime(30065):        at j$.util.stream.c.I0(Unknown Source:10)
E/AndroidRuntime(30065):        at j$.util.stream.U.y(SourceFile:0)
E/AndroidRuntime(30065):        at j$.util.stream.c.L0(SourceFile:0)
E/AndroidRuntime(30065):        at j$.util.stream.k2.forEachOrdered(SourceFile:0)
E/AndroidRuntime(30065):        at qa.e1.m0(Unknown Source:70)
E/AndroidRuntime(30065):        at qa.e1.r(Unknown Source:13)
E/AndroidRuntime(30065):        at k1.a.g(Unknown Source:26)
E/AndroidRuntime(30065):        at i1.b$a.run(Unknown Source:210)
E/AndroidRuntime(30065):        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1137)
E/AndroidRuntime(30065):        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:637)
E/AndroidRuntime(30065):        at java.lang.Thread.run(Thread.java:1012)
E/AndroidRuntime(30065): Caused by: java.lang.ExceptionInInitializerError
E/AndroidRuntime(30065):        at k9.n.m(Unknown Source:0)
E/AndroidRuntime(30065):        at k9.n.l(Unknown Source:5)
E/AndroidRuntime(30065):        at ua.a.b(Unknown Source:0)
E/AndroidRuntime(30065):        ... 30 more
E/AndroidRuntime(30065): Caused by: java.lang.IllegalStateException: Failed to create VMBridge instance
E/AndroidRuntime(30065):        at k9.w3.d(Unknown Source:36)
E/AndroidRuntime(30065):        at k9.w3.<clinit>(Unknown Source:0)
E/AndroidRuntime(30065):        ... 33 more

Any help in resolving this issue would be greatly appreciated.

Expected Behavior

No response

How to Reproduce

To reproduce the issue:

  1. Ensure you have the latest versions of the video_player and applovin_max packages in your Flutter app.

    • video_player: ^2.6.1
    • applovin_max: ^2.5.0
  2. Create a screen in your app where you have both the video player and the ad.

  3. Play a video using the video_player package.

  4. Attempt to load an ad using the AppLovin SDK after the video starts playing.

  5. Observe that the app crashes with the following error:

E/AndroidRuntime(30065): FATAL EXCEPTION: pool-16-thread-1
E/AndroidRuntime(30065): Process: com.videodownloader.udownload, PID: 30065
E/AndroidRuntime(30065): java.lang.NoClassDefFoundError: k9.w3
...

Please note that this issue occurs specifically on Android and is not reproducible in debug mode but only in release mode.

It's important to mention that this issue is observed when trying to load the ad after playing a video using the video_player package. Ads load successfully on other screens, indicating that the issue is specific to the combination of video playback and ad loading.

By following the steps above, developers should be able to understand and reproduce the issue in order to investigate and resolve it effectively.

Additional Info

No response

OttomanDeveloper commented 1 year ago

Solution

After extensive research and troubleshooting, I was able to resolve the issue by adding ProGuard rules and modifying the build configuration. Here are the steps I followed:

1. Create a ProGuard Rule File

Under the android/app directory, create a file named proguard-rules.pro. This file will contain the necessary ProGuard rules to retain specific classes and prevent obfuscation.

2. Add ProGuard Rules

Inside the proguard-rules.pro file, add the following ProGuard rules:

-keep class org.schabi.newpipe.extractor.** { *; }
-keep class org.ocpsoft.prettytime.i18n.** { *; }
-keep class org.mozilla.javascript.** { *; }
-keep class org.mozilla.classfile.ClassFileWriter
-keep class com.google.android.exoplayer2.** { *; }
-dontwarn org.mozilla.javascript.tools.**
-dontwarn android.arch.util.paging.CountedDataSource
-dontwarn android.arch.persistence.room.paging.LimitOffsetDataSource
-keep class com.artxdev.** { *; }
-keep class androidx.lifecycle.** { *; }
-keep class org.jaudiotagger.** { *; }
-keep class com.example.audio_tagger.** { *; }
-dontobfuscate

## Flutter wrapper
-keep class io.flutter.app.** { *; }
-keep class io.flutter.plugin.** { *; }
-keep class io.flutter.util.** { *; }
-keep class io.flutter.view.** { *; }
-keep class io.flutter.** { *; }
-keep class io.flutter.plugins.** { *; }

# -keep class com.google.firebase.** { *; } // uncomment this if you are using firebase in the project

-keep class com.arthenica.mobileffmpeg.Config {
    native <methods>;
    void log(long, int, byte[]);
    void statistics(long, int, float, float, long , int, double, double);
}

-keep class com.arthenica.mobileffmpeg.AbiDetect {
    native <methods>;
}

# Rules for OkHttp. Copy-paste from https://github.com/square/okhttp
-dontwarn okhttp3.**
-dontwarn okio.**
-dontwarn javax.annotation.**
-keepnames class okhttp3.internal.publicsuffix.PublicSuffixDatabase
-keepclassmembers class * implements java.io.Serializable {
    static final long serialVersionUID;
    !static !transient <fields>;
    private void writeObject(java.io.ObjectOutputStream);
    private void readObject(java.io.ObjectInputStream);
}

These rules will preserve the necessary classes and prevent any issues related to obfuscation.

3. Modify the Build Configuration

Inside the android/app/build.gradle file, locate the buildTypes section and add the proguardFiles directive under the release build type. Update the configuration as follows:

buildTypes {
    release {
        // TODO: Add your own signing config for the release build.
        // Signing with the debug keys for now, so `flutter run --release` works.

        signingConfig signingConfigs.release
        proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
    }
}

This modification ensures that the ProGuard rules are applied when building the release version of the app.

4. Add Required Repositories

If you're using the newpipeextractor library for playing online videos, make sure to add the following repositories at the top of the android/app/build.gradle file:

repositories {
    maven { url "https://jitpack.io" }
    mavenCentral()
}

These repositories are required to fetch the necessary dependencies for the newpipeextractor library.

By following these steps, I was able to resolve the issue and prevent the app from crashing when loading ads during video playback. These changes ensure that the required classes are retained and prevent any conflicts related to obfuscation.

I hope this solution helps others facing a similar issue.