stevesaliman / gradle-properties-plugin

Gradle plugin to simplify loading project properties from external environment specific files
Apache License 2.0
192 stars 28 forks source link

Per variant resValues not generated with AGP 4.1.1 #37

Closed mbarrben closed 3 years ago

mbarrben commented 3 years ago

Hi!

I'm trying to update my project to AGP 4.1.1 but then I lose all the per variant resValues and BuildConfig properties I define on those subprojects that have the gradle-properties-plugin applied. If I remove the gradle-properties-plugin or rollback AGP to 4.0.1, resValuesand BuildConfig properties per variant are generated again.

I managed to reproduce the issue on a very simple project:

  1. Just create a new blank project from Android Studio 4.1.1 using the wizard.
  2. Then in the app module build.gradle apply the plugin and define some resValues per variant:
    
    plugins {
    id 'com.android.application'
    id 'kotlin-android'
    id 'net.saliman.properties' version '1.5.1'
    }

android { compileSdkVersion 30 buildToolsVersion "30.0.2"

defaultConfig {
    applicationId "com.example.myapplication"
    minSdkVersion 21
    targetSdkVersion 30
    versionCode 1
    versionName "1.0"

    testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"

    resValue "string", "res_value_default", "resValue default"
}

applicationVariants.all { variant ->
    resValue "string", "res_value_variant", "resValue $variant.name"
}

buildTypes {
    release {
        minifyEnabled false
        proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
    }
}
compileOptions {
    sourceCompatibility JavaVersion.VERSION_1_8
    targetCompatibility JavaVersion.VERSION_1_8
}
kotlinOptions {
    jvmTarget = '1.8'
}

}

dependencies { implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version" implementation 'androidx.core:core-ktx:1.2.0' implementation 'androidx.appcompat:appcompat:1.1.0' implementation 'com.google.android.material:material:1.1.0' implementation 'androidx.constraintlayout:constraintlayout:1.1.3' implementation 'androidx.navigation:navigation-fragment-ktx:2.2.2' implementation 'androidx.navigation:navigation-ui-ktx:2.2.2' testImplementation 'junit:junit:4.+' androidTestImplementation 'androidx.test.ext:junit:1.1.1' androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0' }

Then when building the project, the expected result is a `app/build/generated/resValues/debug/values/gradleResValues.xml` file as follows:
```xml
<?xml version="1.0" encoding="utf-8"?>
<resources>

    <!-- Automatically generated file. DO NOT MODIFY -->

    <!-- Value from the variant -->
    <string name="res_value_variant" translatable="false">resValue debug</string>
    <!-- Value from default config. -->
    <string name="res_value_default" translatable="false">resValue default</string>

</resources>

But instead, only the value from the default config is generated:

<?xml version="1.0" encoding="utf-8"?>
<resources>

    <!-- Automatically generated file. DO NOT MODIFY -->

    <!-- Value from default config. -->
    <string name="res_value_default" translatable="false">resValue default</string>

</resources>

Thanks in advance!

HeyAlex commented 3 years ago

Same thing in my project. @mbarrben did you find a workaround for this problem?

mbarrben commented 3 years ago

Unfortunately I eventually removed this plugin from my project since I didn't need it any more. However I suspect this issue is most likely related to an AGP 4.1 issue already tracked by Google and fixed on AGP 4.2. Therefore I'm closing this issue.