Gradle Extended Build Plugin: Can't Call CanRead ()?
I am trying to use Gradle Plugin Advanced Version in my application. I did it as described on the GitHub page:
-
I added this code to my build.gradle app:
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 do Generate a Signed APK
, I get an error while doing the task :app:assembleRelease
:
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 to move the code in step # 1 to Project build.gradle, but I still get the same error.
source to share
This seems to be a simple error that causes NullPointerException
.
The versionPropsFile
class property is VersionCodeOptions
initialized only in the getVersionCode
getter.
But the plugin tries to access this property before it calls getVersionCode
, and thus gets a null file reference which fails when it checks if it is canRead()
.
The workaround is pretty simple: all you have to do is make a dummy getter call getVersionCode
right after configuring the plugin, for example:
In the build.gradle project:
advancedVersioning {
nameOptions {
}
codeOptions {
versionCodeType VersionCodeType.AUTO_INCREMENT_ONE_STEP
dependsOnTasks 'release'
}
}
println advancedVersioning.versionCode
After printing out the version code, I call getter and thereby create the file.
source to share