I'm trying to use Gradle Advanced Build Version Plugin in my app. I did as described in the GitHub page:
I added this code in my app's build.gradle:
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'org.moallemi.gradle.advanced-build-version:gradle-plugin:1.5.0'
}
}
apply plugin: 'org.moallemi.advanced-build-version'
Then, at the end of the same file, I configured advancedVersioning like this:
advancedVersioning {
outputOptions {
renameOutput true
nameFormat '${projectName}-${buildType}-${versionName}'
}
}
However, when I Generate a Signed APK, I get an error while executing :app:assembleRelease task:
Error:
02:06:47.075 [ERROR] [org.gradle.BuildExceptionReporter]
02:06:47.076 [ERROR] [org.gradle.BuildExceptionReporter] FAILURE:
Build failed with an exception.
02:06:47.076 [ERROR] [org.gradle.BuildExceptionReporter]
02:06:47.077 [ERROR] [org.gradle.BuildExceptionReporter] * What went wrong:
02:06:47.077 [ERROR] [org.gradle.BuildExceptionReporter] A problem occurred
configuring project ':app'.
02:06:47.077 [ERROR] [org.gradle.BuildExceptionReporter]
Cannot invoke method canRead() on null object
02:06:47.078 [ERROR] [org.gradle.BuildExceptionReporter]
02:06:47.078 [ERROR] [org.gradle.BuildExceptionReporter] * Try:
02:06:47.078 [ERROR] [org.gradle.BuildExceptionReporter] Run with --stacktrace option to
get the stack trace.
This is on Android Studio 1.3 with gradle plugin 1.2.3. I tried moving the code in step #1 to the Project's build.gradle but I still get the same error.
It seems to be a simple bug that causes NullPointerException.
The versionPropsFile property of the VersionCodeOptions class is only initialized in the getVersionCode getter.
But the plugin tries to access this property before it calls to getVersionCode, and thus receiving a null file reference, which crashes when it check whether it canRead().
The workaround is pretty simple: All you need to do is to make a dummy call to the getVersionCode getter right after you configure the plugin, like this:
In the project's build.gradle:
advancedVersioning {
nameOptions {
}
codeOptions {
versionCodeType VersionCodeType.AUTO_INCREMENT_ONE_STEP
dependsOnTasks 'release'
}
}
println advancedVersioning.versionCode
By printing the version code I'm invoking the getter and thus creating the file object.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With