1

I am trying to build a release assembly with R8. There are many modules in the application. The navigation component is used to navigate between fragments. There are some fragments that are in one module, but are used in several. Because of this, 2 CitiesBottomDialogFragmentArgs classes are generated in the same directory. There are many such classes. In the debug assembly, this problem does not arise. How can this problem be solved?

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

Error: /home/mikhail/StudioProjects/android_projects/vlife_android3/loyalty/build/intermediates/runtime_library_classes_jar/release/classes.jar:com.example/profile/presentation/ui/cities/CitiesBottomDialogFragmentArgs.class, 

Type kz.viled.vlife.profile.presentation.ui.cities.CitiesBottomDialogFragmentArgs is defined multiple times: /home/mikhail/StudioProjects/android_projects/vlife_android3/loyalty/build/intermediates/runtime_library_classes_jar/release/classes.jar:com.example/profile/presentation/ui/cities/CitiesBottomDialogFragmentArgs.class, /home/mikhail/StudioProjects/android_projects/vlife_android3/profile/build/intermediates/runtime_library_classes_jar/release/classes.jar:com.example/profile/presentation/ui/cities/CitiesBottomDialogFragmentArgs.class

Gradle

apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
apply plugin: 'kotlin-kapt'
apply plugin: "androidx.navigation.safeargs"
apply plugin: 'com.google.gms.google-services'

android {
   

    compileSdkVersion 29
    buildToolsVersion '29.0.3'

    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }

    kotlinOptions {
        jvmTarget = "1.8"
    }

    defaultConfig {
        applicationId "..."
        minSdkVersion 24
        targetSdkVersion 29
        versionCode VERSION_CODE
        versionName VERSION_NAME
        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
        vectorDrawables.useSupportLibrary = true
    }

    lintOptions {
        checkReleaseBuilds false
        abortOnError false
        disable 'MissingTranslation'
    }

    buildFeatures {
        dataBinding = true
    }

    buildTypes {
        release {
            minifyEnabled true
            shrinkResources true
            multiDexEnabled true
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
            signingConfig signingConfigs.vlife
            debuggable false // In release change to false
        }
        debug {
            minifyEnabled false
            shrinkResources false
           
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
        }
    }

    flavorDimensions "version"

    productFlavors {
        demo {
            dimension "version"
            applicationIdSuffix ".test"
            resValue "string", "app_name", "... Test"
            signingConfig signingConfigs.release
            applicationId '...'
        }
        full {
            dimension "version"
            applicationIdSuffix ".release"
            resValue "string", "app_name", "..."
            signingConfig signingConfigs.debug
            applicationId '...'
        }
    }

    dynamicFeatures = []

}

androidExtensions {
    experimental = true
}

Tried setting up proguard to get rid of duplication. It did not help. Or I used the wrong settings? For each module, added such a set of rules to the proguard-rules.pro

-keep class com.crashlytics.** { *; }
-keepnames class com.crashlytics.** { *; }
-dontwarn com.crashlytics.**

-keep class com.** { *; }
-keepnames class com.** { *; }
-dontwarn com.**

-keep class javax.** { *; }
-keepnames class javax.** { *; }
-dontwarn javax.**

-keep class java.** { *; }
-keepnames class java.** { *; }
-dontwarn java.**

-keep class android.** { *; }
-keepnames class android.** { *; }
-dontwarn android.**

-keep class retrofit2.** { *; }
-keepnames class retrofit2.** { *; }
-dontwarn retrofit2.**

-keep class io.** { *; }
-keepnames class io.** { *; }
-dontwarn io.**

-keep class ru.** { *; }
-keepnames class ru.** { *; }
-dontwarn ru.**

-keep class afu.** { *; }
-keepnames class afu.** { *; }
-dontwarn afu.**

-keep class org.** { *; }
-keepnames class org.** { *; }
-dontwarn org.**

-keep class net.** { *; }
-keepnames class net.** { *; }
-dontwarn net.**


-keep class okhttp3.** { *; }
-keepnames class okhttp3.** { *; }
-dontwarn okhttp3.**


-keep class android.support.** { *; }
-keep interface android.support.** { *; }
-keep class androidx.** { *; }
-keep interface androidx.** { *; }
-keepattributes SourceFile,LineNumberTable

-dontnote com.example.profile.presentation.ui.cities.CitiesBottomDialogFragmentArgs
-dontwarn com.example.profile.presentation.ui.cities.CitiesBottomDialogFragmentArgs
-ignorewarnings com.example.profile.presentation.ui.cities.CitiesBottomDialogFragmentArgs

Updated

 dependencies {
    classpath 'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.8.4'
    classpath 'com.github.dcendents:android-maven-gradle-plugin:2.1'
    classpath "com.android.tools.build:gradle:4.0.1"
    classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:1.3.72"
    classpath "androidx.navigation:navigation-safe-args-gradle-plugin:2.3.0"
    classpath "com.google.gms:google-services:$googleGms"

    
}
Witerius
  • 11
  • 2
  • Well, i'm found 2 solutions: 1) https://stackoverflow.com/questions/58988557/issue-with-navigation-component-duplicate-navargs 2) Make the fragment from the first module open and inherit it in the second module for the dummy class. And use this dummy class in navigation graph – Witerius Aug 01 '20 at 13:14

0 Answers0