I have the following task in my Android build.gradle file which copies my built APK file for me:
/**
* Copies the final release APK into the project root folder.
*/
task copyRelease(type: Copy) {
// define output files exactly to work around a file locking issue
outputs.files.setFrom(file("../app-release.apk"))
from "build/outputs/apk/app-release.apk"
into ".."
}
This has been working for a long time and broke today when doing Android Studio's suggested update:
Android Gradle plugin v2.3.0 (from v2.2.3)
Gradle v3.3 (from v2.14.1)
Running the Grade build now gives the following error on the line outputs.files.setfrom(...):
No signature of method: org.gradle.api.internal.tasks.DefaultTaskOutputs$TaskOutputUnionFileCollection.setFrom() is applicable for argument types: (java.io.File) values: [..\app-release.apk]
Possible solutions: sort()
To summarise, it seems like TaskOutputUnionFileCollection.setFrom() no longer takes File parameters.
But I do not know how to migrate this code to the new version and a look through the source class has not helped me.
I have looked at the Android Gradle plugin Known Issues page as well as the Gradle 3.3. Release Notes, and found no direct reference to this.
I could not find a direct & exact translation of the above code without implementing a workaround. The problem lies in using the root folder of the project for the destination of the copy command.
The workaround was to create a separate folder ..\release and then the following code works fine:
/**
* Copies the final release APK into the project root folder.
*/
task copyRelease(type: Copy) {
from "build/outputs/apk"
into "../release"
include "app-release.apk"
}
Related
I got some source code and was asked to build it. It was a Gradle project. So I changed to the project directory and ran:
$ gradle clean assemble
and the following error came up:
...
* What went wrong:
A problem occurred evaluating root project 'pcase'.
> Could not get unknown property 'postgresql.jdbc' for root project 'pcase' of type org.gradle.api.Project.
...
There is a settings.gradle file in the project folder too. It contains:
rootProject.name = 'pcase'
I took a look at build.gradle and found lots of occurrences like
${project['x']}
For example:
buildscript {
dependencies {
...
// FlywayDB, JOOQ.
classpath "org.postgresql:postgresql:${project['postgresql.jdbc']}"
classpath "org.flywaydb:flyway-gradle-plugin:${project['flywaydb.plugin.version']}"
classpath "nu.studer:gradle-jooq-plugin:${project['jooq.plugin.version']}"
...
What could be ${project['x']}? Looks like associative array in bash and the build script tries to get the value of the key 'x'.
But I didn't find the place in code where this array would be declared and initialized.
The question is: Is the project buildable or is it better to consult the company that worked at it before me?
From the information provided, the project is perfectly buildable, to some certain extend. First of all, project['a.b.c'] is Groovy syntax to access properties from the project object. They're referred to as project properties.
They can be set via
Project properties via command line: gradle -Ppostgresql.jdbc=x.y.z
System properties via command line: gradle -Dorg.gradle.project.postgresql.jdbc=x.y.z
System properties via gradle.properties: org.gradle.project.postgresql.jdbc=x.y.z
All 3 properties (postgresql.jdbc, flywaydb.plugin.version, jooq.plugin.version) denote the version numbers of the particular build script dependencies. However, which versions to use best is beyond my knowledge. I would certainly consult the respective project websites, Maven artifact search or simply ask the company.
org.postgresql:postgresql is the database JDBC driver and certainly depends on the database version.
org.flywaydb:flyway-gradle-plugin is for database migrations. Try with the latest version.
I wasn't able to find gradle-jooq-plugin on Maven central. It's most likely available on the Gradle Plugin Portal.
I'm trying to apply precompile script gradle.kts file (gradle.kts script is put in buildSrc/main/java. everything work normally except that i can not add a plugin with version. for example my test.gradle.kts
plugins {
id("io.gitlab.arturbosch.detekt") version "1.1.1"
}
but always got the error
Invalid plugin request [id: 'io.gitlab.arturbosch.detekt', version: '1.1.1']. Plugin requests from precompiled scripts must not include a version number. Please remove the version from the offending request and make sure the module containing the requested plugin 'io.gitlab.arturbosch.detekt' is an implementation dependency of project ':buildSrc'.
And also I cannot the class to configure extension
For example, this normally configuration is not working
configure<DetektExtension>
How can we specify plugin version in precompile script? and how can we configure the plugin?
Without being able to see your build structure and file tree I can only answer based on how I'm understanding your question. Based on the error message you are receiving, you should be declaring the plugin dependency in the project level build.gradle.kts:
plugins {
id("io.gitlab.arturbosch.detekt") version "1.1.1"
}
Then in your buildSrc/build.gradle implement it like so:
plugins {
`io.gitlab.arturbosch.detekt`
}
Gradle has samples on GitHub, from which I drew this example, here:
https://github.com/gradle/kotlin-dsl-samples/tree/master/samples/multi-kotlin-project-with-buildSrc
afterburner.fx for JavaFX 8 is a minimalistic (3 classes) JavaFX MVP framework based on Convention over Configuration and Dependency Injection created by Adam Bien.
afterburner.fx use Maven 3.
I would like to use it with Gradle.
How to use Afterburner.fx with Gradle instaed of Maven 3, while leaving the original project structure of afterburner.fx ?
In the build.gradle File add dependencies
dependencies {
compile group: 'com.airhacks', name:'afterburner.fx', version: afterburnerfxVersion
}
In the build.gradle File add the additional Resources (.fxml , .css , .properties)
sourceSets.main.resources.srcDirs("src/main/java").includes.addAll(["**/*.fxml", "**/*.css", "**/*.properties"])
and (re-)add all the standard Resources (in the resources folder)
sourceSets.main.resources.srcDirs("src/main/resources").includes.addAll(["**/*.*"])
Update for Gradle Version 6.8.1 : if you run gradlew with --warning-mode all there is a deprecated Message:
Copying or archiving duplicate paths with the default duplicates strategy has been deprecated. This is scheduled to be removed in Gradle 7.0.
Solution
add this line:
// from https://docs.gradle.org/6.8.1/userguide/upgrading_version_5.html#implicit_duplicate_strategy_for_copy_or_archive_tasks_has_been_deprecated
// and https://docs.gradle.org/current/userguide/java_plugin.html
// Java Plugin Task processResources(type: Copy)
processResources.duplicatesStrategy = DuplicatesStrategy.INCLUDE // allow duplicates
Thanks, this helped me a lot. I added the short form of it to dependencies:
compile 'com.airhacks:afterburner.fx:1.6.0'
Additionally I added a second line to include the files from the resources folder and not only from /java. I also added **/*.png to include png files because new Image("filename.png") wasn't working anymore.
sourceSets.main.resources.srcDirs("src/main/java").includes.addAll(["**/*.fxml", "**/*.css", "**/*.properties", "**/*.png"])
sourceSets.main.resources.srcDirs("src/main/resources").includes.addAll(["**/*.fxml", "**/*.css", "**/*.properties", "**/*.png"])
I don't know why the above two lines broke the default behavior - seems like I have to add every new file type to the above lines. :/ If anyone has a better solution please tell me.
In my Android Studio project, I added the following build type to the build.gradle file:
jnidebug.initWith(buildTypes.debug)
jnidebug {
packageNameSuffix ".jnidebug"
jniDebuggable true
}
The documentation at:
http://tools.android.com/tech-docs/new-build-system/user-guide
says:
For each Build Type, a new matching sourceSet is created, with a
default location of src/<buildtypename>/
But when I resync gradle, the source code folder src/jnidebug never gets created. What am I doing wrong?
The documentation says that for each build type, a source set (which is a logical concept/domain object) is created and configured with a default location. It doesn't say that a source directory is created. You'll probably have to create the directory yourself. (Android Studio could certainly help with that, so perhaps file a feature request.)
I am building an Android Library project using the Android Gradle plugin (version 0.9.2) and it appears to have a bug (reported) in that while a "provided" dependency is correctly handled (not included) in the generated aar artifact, that dependency is incorrectly included in the generated debug test apk file.
It strikes me that a reasonable workaround is to remove the dependency jar file that is added by the :preDexDebugTest task as the last step for that task. But this task is dynamically generated so getting a handle to it is eluding me at the moment, hence the question.
In your app's build.gradle file, add
afterEvaluate {
def preDexDebugTest = tasks['preDexDebugTest']
// Do something with preDexDebugTest ...
}
That way it should be possible to operate on the preDexDebugTest task.