0

Since update to Android Studio 3.3 we get a weird warning with some legacy code about encrypted gradle parameters.

In build.gradle we have this line:

apply from: "encryption.gradle"

In encryption.gradle we have this content:

afterEvaluate {
    android.applicationVariants.all { variant ->
        def pwd = "";
        variant.productFlavors.each { flavor ->
            if (flavor.ext.has("pwd1")) {
                pwd = flavor.ext.pwd1
            }
        }
        if (pwd.isEmpty() && variant.buildType.ext.has("pwd2")) {
            pwd = variant.buildType.ext.pwd2
        }
        variant.resValue 'string', 'pwd', encryptPassword(pwd, variant.signingConfig, variant.applicationId)
    }
}

def String encryptPassword(String password, signingConfig, String applicationId) {
    ...
}

In the code we use it like this:

getString(R.string.pwd)

And since the AS update we get the following error:

Cannot resolve symbol 'pwd'

When compiling/building the project everything runs fine because it can find the parameter. But when working in the IDE, all files that try to use R.string.pwd are marked red and show the error message, which is pretty annoying.

Any way to make this go away easily? SuppressWarnings("all") and SuppressLint("all") are not helping.

Is afterEvaluate the right place to do this or would it be better somehow in the defaultConfig section of build.gradle?

Daniel Brown
  • 1,134
  • 1
  • 13
  • 27

1 Answers1

1

Even i was facing similar issues. so i reverted my gradle to 3.2.1 and it works as expected, it might be a technical glitch/issue with gradle 3.3

While i was on gradle 3.3 i tried invalidating cache for android studio, restarted it etc, but nothing solved the issue.

  • I get ERROR: Minimum supported Gradle version is 4.10.1. Current version is 3.2.1. :( – Daniel Brown Jan 25 '19 at 11:25
  • Which Android Studio version are you using now? And what's your Gradle Version and Android Plugin Version? – Daniel Brown Jan 25 '19 at 11:56
  • I tried different version now and couldn't get it to work, so our problem seems different. But thx for answering, could help somebody else. – Daniel Brown Jan 28 '19 at 14:35
  • I'm using android studio 3.3 and have setup distributionUrl=https\://services.gradle.org/distributions/gradle-4.6-all.zip classpath 'com.android.tools.build:gradle:3.2.1' – Shahbaz sultan Jan 28 '19 at 15:26
  • Nope, same problem with those versions (Cannot resolve symbol). I guess because the compilation rules have changed and the R-file is not created for the IDE anymore. What helps is downloading Android Studio 3.2.1, there I see the variable in the R-file in the build-folder and all is fine. But that is not a long term solution. – Daniel Brown Jan 29 '19 at 10:44