AppLovin / AppLovin-MAX-Ad-Review-SDK-Android

2 stars 0 forks source link

Stop keeping all `androidx.**` classes in generated ProGuard rules #7

Open Goooler opened 4 months ago

Goooler commented 4 months ago

The ProGuard file generated by this plugin is located at project_dir/.safedk/proguard-safedk.pro, it looks like:

-keep class androidx.** { *; }
-keep class android.support.multidex.** { *; }
-keep class android.support.v4.app.** { *; }
-keep class com.google.android.gms.location.FusedLocationProviderApi { *; }
-keep class com.google.android.gms.location.LocationListener { *; }
...

contains -keep class androidx.** { *; } to keep all AndroidX classes, significantly increasing the generated APK file sizes. Usually, rules are bundled in AndroidX packages, we don't need to add any extra ones. Please remove it.

Goooler commented 4 months ago

Workaround for AppLovinQualityServiceGradlePlugin:4.13.6:

/**
 * TODO: remove this once https://github.com/AppLovin/AppLovin-MAX-Ad-Review-SDK-Android/issues/7 is fixed.
 */
def removeProguardRules = tasks.register('removeProguardRules') {
    def file = rootProject.file(".safedk/proguard-safedk.pro")
    if (file.exists()) {
        def newRules = file.readLines().findAll { !it.contains("androidx.**") }.join('\n')
        file.text = newRules
    }
}

tasks.withType(com.android.build.gradle.internal.tasks.R8Task).configureEach {
    dependsOn(removeProguardRules)
}

Workaround for AppLovinQualityServiceGradlePlugin:5.2.7:

def removeProguardRules = tasks.register('removeProguardRules') {
    def file = rootProject.file(".safedk/proguard-safedk.pro")
    if (file.exists()) {
        def redundantRules = [
            "-keep class androidx.** {",
            "*** startActivityForResult(***);",
            "*** startActivity(***);",
            "}",
        ]
        def newRules = file.readLines().collect { it.trim() }
        newRules.removeAll(redundantRules)
        file.text = newRules.join('\n')
    }
}
github-actions[bot] commented 1 week ago

This issue is stale because it has been open for 30 days with no activity.

Goooler commented 1 week ago

It's alive.