I used to copy 'compile' dependencies to a specific folder using this simple gradle task :
task copyLibs(type: Copy) { from configurations.compile into "$project.rootDir/reports/libs/" }
But it stopped working just after upgrading my Android project using gradle plugin 3.0.1 for Android Studio and Gradle tool to 4.1. As the dependency configuration 'compile' is now deprecated by https://developer.android.com/studio/build/gradle-plugin-3-0-0-migration.html#new_configurations I changed it to 'implementation'. However, I am not able to use my copyLibs task as resolving configuration 'implementation' directly is not allowed as per Gradle build error output :
$ ./gradlew.bat clean build FAILURE: Build failed with an exception. * What went wrong: Could not determine the dependencies of task ':app:copyLibs'. > Resolving configuration 'implementation' directly is not allowed * Try: Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. * Get more help at https://help.gradle.org BUILD FAILED in 1s
See following my current build.gradle file for app module : apply plugin: 'com.android.application'
android { compileSdkVersion 26 defaultConfig { applicationId "newgradle.com.testingnewgradle" minSdkVersion 21 targetSdkVersion 26 versionCode 1 versionName "1.0" testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" } buildTypes { release { minifyEnabled false proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' } } } dependencies { implementation fileTree(dir: 'libs', include: ['*.jar']) implementation 'com.android.support:appcompat-v7:26.1.0' implementation 'com.android.support:support-v4:26.1.0' implementation 'com.android.support:design:26.1.0' implementation 'com.android.support.constraint:constraint-layout:1.0.2' testImplementation 'junit:junit:4.12' androidTestImplementation 'com.android.support.test:runner:1.0.1' androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.1' } task copyLibs(type: Copy) { from configurations.implementation into "$project.rootDir/reports/libs/" } build.dependsOn copyLibs
If I use 'compile' it works but I would like to be compliant with the latest recommendation on this plugin the usage.
I need help to upgrade my copyLibs task in order to work as before upgrading my enviromment. I was using gradle plugin 2.2.3 for Android Studio and Gradle tool 2.14.1.
Update Gradle For the best performance, you should use the latest possible version of both Gradle and the plugin. You can specify the Gradle version in either the File > Project Structure > Project menu in Android Studio, or update your Gradle version using the command line.
A “configuration” is a named grouping of dependencies. A Gradle build can have zero or more of them. A “repository” is a source of dependencies. Dependencies are often declared via identifying attributes, and given these attributes, Gradle knows how to find a dependency in a repository.
In Eclipse, select File > Export. In the window that appears, open Android and select Generate Gradle build files. Select the project you want to export for Android Studio and click Finish.
I make configuration can resolved, so no exception get dependcenies's file
configurations.implementation.setCanBeResolved(true) configurations.api.setCanBeResolved(true) println configurations.implementation.resolve() println configurations.api.resolve()
instead of using configurations.implementation
, the best option is to use configurations.runtimeClasspath
.
You can also think about: compileClasspath default
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