Android Gradle Plugin 7 LibraryBuildType no longer has isDebuggable property

Viewed 587

I am in the process of upgrading from Android Gradle 4.1.3 to 7.0.2. One of the things I've noticed is that for my com.android.library module, the

getByName("foo") {
  ...
}

now has a receiver type of LibraryBuildType as opposed to BuildType that it used to. This LibraryBuildType no longer has the isDebuggable property, which BuildType used to have.

The official android docs mention that

If your app depends on a library module that you also want to debug, that library must also be packaged with debuggable true so it retains its debug symbols.

Obviously these docs are out of date, but what gives? Is debuggable true no longer needed for library modules?

I've found the git log for LibraryBuildType, which shows it was added around April of 2020, but I have not found any information about this in the android gradle plugin release notes

3 Answers

LibraryTaskManager used libraryVariant.getDebuggable

From what I found, the source code of LibraryTaskManager still uses the libraryVariant.getDebuggable() that is produced from buildType&productFlavor. I'm not sure why the debuggable / isDebuggable option is not availble from LibraryBuildType, however if anyone is looking for the workaround, use the code below:

// library's build.gradle.kts
buildTypes {
    named("debug") {
        (this as com.android.build.gradle.internal.dsl.BuildType).isDebuggable = false
    }
}

I meet same problem, so used another workaround.

Use initWith() with debug buildType makes new type to debuggable too.

    create("foo") {
        // Apply debug type setting by initWith()
        initWith(getByName("debug"))
    }

But I think Gradle kts should add debuggable property to build type.

I think it makes sense to remove that property for libraries, given that you should define debuggable at the application level.

Related