Android Studio proguard handling in multi-library projects

后端 未结 2 889
旧巷少年郎
旧巷少年郎 2020-12-07 15:49

I have an application that uses an externally referenced library (that is, the directory of the library is in the same level as the application - it is not copied inside the

相关标签:
2条回答
  • 2020-12-07 16:29

    After some searching I found the answer. If you are using external/separate source libraries with your main project/application, you should not use a proguard on the library modules. Instead, you replace the following,

    buildTypes {
        release {
            minifyEnabled true
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-project.txt'
        }
        debug {
            minifyEnabled false
        }
    }
    

    with the following (in the build.gradle of the library/libraries):

    buildTypes {
        release {
            consumerProguardFiles 'proguard-project.txt'
        }
    }
    

    where proguard-project.txt is the file that contains the proguard rules for your library project. When building the application (either in debug or release mode), the compiler will take care of all the rules (in the library and in the application).

    0 讨论(0)
  • 2020-12-07 16:29

    I think you need define proguard-rules for your libraries. Usually they are in the library docs.

    (For example have a look at my answer here for ButterKnife lib: link)

    0 讨论(0)
提交回复
热议问题