I am importing a very old android project which is not working in my latest version of Android studio when I tried to import , it gave me error straight away-
ERROR: Unsupported method: GradleProject.getProjectDirectory().
The version of Gradle you connect to does not support that method.
To resolve the problem you can change/upgrade the target version of Gradle you connect to.
Alternatively, you can ignore this exception and read other information from the model.
Thus I tried to upgrade the gradle version but it started to give other additional errors!
My build.gradle files are as follows-
apply plugin: 'com.android.application'
android {
compileSdkVersion 21
buildToolsVersion "21.1.2"
packagingOptions {
exclude 'META-INF/DEPENDENCIES.txt'
exclude 'META-INF/DEPENDENCIES'
exclude 'META-INF/dependencies.txt'
exclude 'META-INF/LICENSE.txt'
exclude 'META-INF/LICENSE'
exclude 'META-INF/license.txt'
exclude 'META-INF/LGPL2.1'
exclude 'META-INF/NOTICE.txt'
exclude 'META-INF/NOTICE'
exclude 'META-INF/notice.txt'
}
defaultConfig {
applicationId "com.abc.xyz"
minSdkVersion 16
targetSdkVersion 16
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
}
}
}
repositories { mavenCentral() }
dependencies {
compile 'com.google.android.gms:play-services:7.3.0'
compile 'com.android.support:support-v4:21.0.3'
compile 'com.google.code.gson:gson:2.3.1'
compile files('libs/volley.jar')
compile 'com.facebook.android:facebook-android-sdk:4.0.0'
compile group: 'org.apache.httpcomponents' , name: 'httpclient-android' , version: '4.3.5'
compile (group: 'org.apache.httpcomponents' , name: 'httpmime' , version: '4.3.6') {
exclude module: 'org.apache.httpcomponents:httpclient'
}
}
And project level build.gradle file-
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:1.2.2'
}
}
allprojects {
repositories {
jcenter()
}
}
Since it is very old I failed several times trying to upgrade the versions of the support libraries but in the old code the old version of dependencies are used and it is impossible to refactor such a huge code base.
what to do in this case!
Any help is very much appreciated
My solution
dependencies {
classpath 'com.android.tools.build:gradle:4.0.0'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
classpath 'com.google.gms:google-services:4.2.0'
}
Related
I am trying to load an APP. But I am getting an error
Build file 'F:\Android Studio Projects\SalesManagement-Agent\app\build.gradle' line: 30
A problem occurred evaluating project ':app'.
Could not find method implementation() for arguments [directory 'libs'] on project ':app'.
Gradle
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:1.0.0'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
jcenter()
}}
And
apply plugin: 'com.android.application'
android {
compileSdkVersion 30
buildToolsVersion "21.1.2"
defaultConfig {
applicationId "com.example.anik.agent"
minSdkVersion 14
targetSdkVersion 30
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
packagingOptions {
exclude 'META-INF/DEPENDENCIES'
exclude 'META-INF/NOTICE'
exclude 'META-INF/LICENSE'
exclude 'META-INF/LICENSE.txt'
exclude 'META-INF/NOTICE.txt'
}
}
dependencies {
implementation fileTree(include: ['*.jar'], dir: 'libs')
implementation 'androidx.appcompat:appcompat:1.2.0'
implementation 'org.apache.httpcomponents:httpcore:4.4.10'
implementation('org.apache.httpcomponents:httpmime:4.5.6') {
exclude module: 'httpclient'
}
}
Any help would be highly appreciated.
Try build-tools 30.0.3 and make sure the Gradle plugin is rather current. Back then keyword implementation didn't exist and was called compile (which is deprecated and will be removed in Gradle 7).
Please check the folder under "app", there needs a folder named "libs".
Suggest change your build-tool-version(ex: 29.0.3) and gradle version(ex: 4.1.2) too.
I've cloned a github repository because I wanted to study the code, but when I tried to build it in Android Studio, I ran into some trouble.
After adding the google maven repository (as prompted by Android Studio) and updating both the Gradle Plugin Version and the Grade Version (to 3.5.2 and to 5.4.1, respectively), the build fails because of the following error:
Cause: duplicate entry: META-INF/MANIFEST.MF
And this, to be more specific:
Caused by: java.util.zip.ZipException: duplicate entry: META-INF/MANIFEST.MF
Here is my project level build.gradle file:
buildscript {
repositories {
jcenter()
google()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.5.2'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
jcenter()
maven {
url 'https://maven.google.com'
}
}
}
Here's my module build.gradle file (before trying anything):
apply plugin: 'com.android.application'
android {
compileSdkVersion 22
buildToolsVersion '28.0.3'
defaultConfig {
applicationId "com.thelittlenaruto.supportdesignexample"
minSdkVersion 11
targetSdkVersion 22
versionCode 1
versionName "1.0"
}
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:22.2.1')
implementation ('com.android.support:design:22.2.1')
implementation 'com.github.frankiesardo:linearlistview:1.0.1#aar'
}
Here's what I've tried so far:
Adding the following to the android section of my module build.gradle file:
sourceSets {
main{
java{
exclude '**/META-INF/MANIFEST'
exclude '**/META-INF/MANIFEST.MF'
exclude 'META-INF/MANIFEST'
exclude 'META-INF/MANIFEST.MF'
exclude '!META-INF/MANIFEST.MF'
}
}
}
Adding this:
sourceSets.main.res.filter.exclude 'META-INF/MANIFEST'
sourceSets.main.res.filter.exclude 'META-INF/MANIFEST.MF'
Also this:
packagingOptions {
apply plugin: 'project-report'
exclude '**/META-INF/MANIFEST'
exclude '**/META-INF/MANIFEST.MF'
exclude 'META-INF/MANIFEST'
exclude 'META-INF/MANIFEST.MF'
exclude '!META-INF/MANIFEST.MF'
}
And this:
packagingOptions {
pickFirst '**/META-INF/MANIFEST'
pickFirst '**/META-INF/MANIFEST.MF'
pickFirst 'META-INF/MANIFEST'
pickFirst 'META-INF/MANIFEST.MF'
pickFirst '!META-INF/MANIFEST.MF'
}
This:
aaptOptions {
ignoreAssetsPattern "!META-INF/MANIFEST.MF"
ignoreAssetsPattern "META-INF/MANIFEST.MF"
}
I think I've tried mostly everything in this question:
How to exclude certain files from Android Studio gradle builds?
Nothing worked.
After searching for a solution, I think the problem is that I have duplicated dependencies. So I've tried the following:
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation ('com.android.support:appcompat-v7:22.2.1'){
exclude module: 'support-v4'
}
implementation ('com.android.support:design:22.2.1')
implementation 'com.github.frankiesardo:linearlistview:1.0.1#aar'
}
And this:
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation ('com.android.support:design:22.2.1'){
exclude module: 'support-v7'
}
implementation 'com.github.frankiesardo:linearlistview:1.0.1#aar'
}
I still get the same error.
What am I doing wrong?
As Rajen Raiyarela said, go to File->Project Structure->Project->Android Gradle Plugin Version and downgrade it from 3.5.2 to 3.5.1.
Set project dependencies to:
classpath 'com.android.tools.build:gradle:3.5.3'
or latest one.
Note: by doing this, my problem has been resolved.
This issue is happening because of duplicate dependencies.
Check for multiple dependencies in the Gradle app.
Either package it once or not at all:
android {
packagingOptions {
pickFirst "META-INF/MANIFEST.MF"
// exclude "META-INF/MANIFEST.MF"
}
}
as #rubo77 says and after my confirmation:
Latest solution
Upgrade gradle version
eg:
from 3.5.2 to 3.5.3
from 3.5.2 to 3.5.4
Obsolete solution:
downgrade from 3.5.2 to 3.5.1
my choice is : upgrade from 3.5.2 to 3.5.4
build.gradle:
dependencies {
// classpath 'com.android.tools.build:gradle:3.5.2'
// classpath 'com.android.tools.build:gradle:3.5.3'
classpath 'com.android.tools.build:gradle:3.5.4'
}
I'm developing an app on Android studio, but when I tried to run Firebase FCM sdk,
I got the message: Version: 7.8.0 is lower than the minimum version (9.0.0) required for google-services plugin.
How can I fix it?
My build.gradle:
apply plugin: 'com.android.application'
android {
compileSdkVersion 23
useLibrary 'org.apache.http.legacy'
defaultConfig {
applicationId "com.example.test"
minSdkVersion 9
targetSdkVersion 20
versionCode 10096
versionName "1.0.9.6"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
// Fixes "Duplicate files copied in APK" build bug
packagingOptions {
exclude 'META-INF/DEPENDENCIES.txt'
exclude 'META-INF/LICENSE.txt'
exclude 'META-INF/NOTICE.txt'
exclude 'META-INF/NOTICE'
exclude 'META-INF/LICENSE'
exclude 'META-INF/DEPENDENCIES'
exclude 'META-INF/notice.txt'
exclude 'META-INF/license.txt'
exclude 'META-INF/dependencies.txt'
exclude 'META-INF/LGPL2.1'
}
}
dependencies {
// Pushy SDK
implementation 'com.google.firebase:firebase-messaging:11.8.0'
compile 'me.pushy:sdk:1.0.43'
// AppCompat v7 Dependency
compile 'com.android.support:appcompat-v7:23.4.0'
// Google Play Services Dependencies
compile 'com.google.android.gms:play-services-location:7.8.0'
// All .jar files in ./libs
compile fileTree(dir: 'libs', include: ['*.jar'])
}
apply plugin: 'com.google.gms.google-services'
and my build.gradle-master:
buildscript {
repositories {
jcenter()
google()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.0.1'
classpath 'com.google.gms:google-services:3.1.1'
}
}
allprojects {
repositories {
jcenter()
google()
}
}
Thank you for your help.
As the error log said, you should change the version in build.gradle.
// Google Play Services Dependencies
compile 'com.google.android.gms:play-services-location:9.0.0'
dependencies in Module build.gradle are
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
exclude group: 'com.android.support', module: 'support-annotations'
})
compile 'com.android.support:appcompat-v7:26.+'
compile 'com.android.support.constraint:constraint-layout:1.0.0-alpha7'
compile 'com.android.support:design:26.+'
compile 'org.apache.flink:flink-streaming-java_2.11:1.4.0'
}
but whenever I compile the code it gave me the following error
FAILURE: Build failed with an exception.
* What went wrong: Execution failed for task ':app:transformResourcesWithMergeJavaResForDebug'.
> com.android.build.api.transform.TransformException: com.android.builder.packaging.DuplicateFileException: Duplicate files copied in APK reference.conf File1: /Users/amar/.gradle/caches/modules-2/files-2.1/com.typesafe.akka/akka-actor_2.11/2.4.20/251b1d970698b81dad5aa8b84eec3eea835259d2/akka-actor_2.11-2.4.20.jar File2: /Users/amar/.gradle/caches/modules-2/files-2.1/org.apache.flink/flink-runtime_2.11/1.4.0/c55676f3ca4c7edd82374659471e98b2384868a8/flink-runtime_2.11-1.4.0.jar File3: /Users/amar/.gradle/caches/modules-2/files-2.1/com.typesafe.akka/akka-stream_2.11/2.4.20/7545a4f86cbb372c337dbdb2846110df86a8cc70/akka-stream_2.11-2.4.20.jar File4: /Users/amar/.gradle/caches/modules-2/files-2.1/com.typesafe/ssl-config-core_2.11/0.2.1/3d2e6a36a7427d6f9d3921c91d6ac1f57dc47b57/ssl-config-core_2.11-0.2.1.jar
This problem was solved by following these steps
step # 1 using the dependency from https://mvnrepository.com instead of https://search.maven.org.
step # 2 Also, I found out that as these files are large which crosses the limit of 64K classes that can be included in DEX files, so I have to configure for Multidex details of which are given here
step # 3 most of the issue was being created by Jacktoolchain, so we can disable that and replace it with retro-lambda for which you can follow this tutorial. Make sure to disable Jacktoolchain by commenting or deleting as shown below
// jackOptions { enabled true }
// dexOptions { incremental true }
step # 4 Exclude these packages from packagingOptions as shown below
packagingOptions {
exclude 'META-INF/DEPENDENCIES.txt'
exclude 'META-INF/DEPENDENCIES'
exclude 'META-INF/dependencies.txt'
exclude 'META-INF/LICENSE.txt'
exclude 'META-INF/LICENSE'
exclude 'META-INF/license.txt'
exclude 'META-INF/LGPL2.1'
exclude 'META-INF/NOTICE.txt'
exclude 'META-INF/NOTICE'
exclude 'META-INF/notice.txt'
}
step # 5 You may find it weird, but this hack works like
compile group: 'org.apache.flink', name: 'link-java', version: '1.4.0'
was not working and was giving some error, but it worked when compile is replaced by provided. I don't know why, please let me know if you know
provided group: 'org.apache.flink', name: 'flink-java', version: '1.4.0'
Luckily flink-streaming-java_2.11 library already had provided mentioned in https://mvnrepository.com
provided group: 'org.apache.flink', name: 'flink-streaming-java_2.11', version: '1.4.0'
Final Module build.gradle has these contents
apply plugin: 'com.android.application'
apply plugin: 'me.tatarka.retrolambda'
repositories {
mavenCentral()
}
android {
packagingOptions {
exclude 'META-INF/DEPENDENCIES.txt'
exclude 'META-INF/DEPENDENCIES'
exclude 'META-INF/dependencies.txt'
exclude 'META-INF/LICENSE.txt'
exclude 'META-INF/LICENSE'
exclude 'META-INF/license.txt'
exclude 'META-INF/LGPL2.1'
exclude 'META-INF/NOTICE.txt'
exclude 'META-INF/NOTICE'
exclude 'META-INF/notice.txt'
}
configurations.all {
// Enforces Gradle to only compile the version number you state for all dependencies, no matter which version number the dependencies have stated.
resolutionStrategy.force 'com.google.code.findbugs:jsr305:1.3.9'
}
compileSdkVersion 26
buildToolsVersion "26.0.1"
defaultConfig {
// jackOptions { enabled true }
// dexOptions { incremental true }
multiDexEnabled true
applicationId "com.example.amar.testing"
minSdkVersion 26
targetSdkVersion 26
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
customDebugType {
debuggable true
}
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
}
dependencies {
// not sure if adding compatibility is required here
sourceCompatibility = 1.7
targetCompatibility = 1.7
compile fileTree(dir: 'libs', include: ['*.jar'])
// androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
// exclude group: 'com.android.support', module: 'support-annotations'
// })
compile 'com.android.support:appcompat-v7:26.+'
compile 'com.android.support.constraint:constraint-layout:1.0.0-alpha7'
compile 'com.android.support:design:26.+'
testCompile 'junit:junit:4.12'
// for multidex
compile 'com.android.support:multidex:1.0.0'
// for CEP
provided group: 'org.apache.flink', name: 'flink-java', version: '1.4.0'
provided group: 'org.apache.flink', name: 'flink-streaming-java_2.11', version: '1.4.0'
}
Final Application build.gradle has these contents
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.3.3'
classpath 'me.tatarka:gradle-retrolambda:3.2.3'
apply plugin: 'java'
apply plugin: 'eclipse'
apply plugin: 'idea'
sourceCompatibility = 1.7
targetCompatibility = 1.7
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
jcenter()
}
}
This question already has an answer here:
Duplicate files copied in APK META-INF/maven/com.squareup/otto/pom.xml
(1 answer)
Closed 5 years ago.
Hello people i get the following error when iam trying to run my android app:
Gradle build error, Error:Execution failed for task ':app:transformResourcesWithMergeJavaResForDebug'
com.android.build.api.transform.TransformException:com.android.builder.packaging.DuplicateFileException: Duplicate files copied in APK META/INF/maven/com.squareup.okio/okio/pom.xml
These are my both gradle files:
// Top-level build file where you can add configuration options common to
all sub-projects/modules.
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.1.0'
classpath 'com.google.gms:google-services:3.1.0'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
jcenter()
apply plugin: 'maven'
maven { url 'https://maven.google.com' }
maven {url 'https://maven.fabric.io/public'}
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
And this is the other one:
apply plugin: 'com.android.application'
android {
compileSdkVersion 26
buildToolsVersion "26.0.2"
defaultConfig {
applicationId "com.dp.liveupdatestatus"
minSdkVersion 18
targetSdkVersion 26
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'),
'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:26.1.0'
compile 'com.android.support:design:26.1.0'
compile 'com.android.support:recyclerview-v7:26.1.0'
// This is needed for firebase UI
compile 'com.android.support:support-v4:26.1.0'
compile 'com.android.support:customtabs:26.1.0'
compile 'com.android.support:cardview-v7:26.1.0'
compile 'com.google.firebase:firebase-core:11.4.2'
compile 'com.google.firebase:firebase-database:11.4.2'
compile 'com.google.firebase:firebase-storage:11.4.2'
compile 'com.google.firebase:firebase-crash:11.4.2'
compile 'com.google.firebase:firebase-auth:11.4.2'
compile 'com.google.firebase:firebase-messaging:11.4.2'
compile 'com.firebaseui:firebase-ui:3.1.0'
compile 'com.squareup.picasso:picasso:2.5.2'
}
// Add to the bottom of the file
apply plugin: 'com.google.gms.google-services'
Please help!
android {
......
packagingOptions {
exclude 'META-INF/DEPENDENCIES.txt'
exclude 'META-INF/LICENSE.txt'
exclude 'META-INF/NOTICE.txt'
exclude 'META-INF/NOTICE'
exclude 'META-INF/LICENSE'
exclude 'META-INF/DEPENDENCIES'
exclude 'META-INF/notice.txt'
exclude 'META-INF/license.txt'
exclude 'META-INF/dependencies.txt'
exclude 'META-INF/LGPL2.1'
}
}
add this to exclude the META inf files