I have Android Studio Beta. I created a new project with compile my old modules but when I tried launching the app it did not launch with the message:
Error:
In my case, Unfortunately, neither Michel's nor Suragch's solutions worked for me.
So I solved this issue by doing the following:
In gradle:3.0 the compile configuration is now deprecated and should be replaced by implementation or api. For more information you can read here You can read the official docs at Gradle Build Tool
The compile configuration still exists but should not be used as it will not offer the guarantees that the api and implementation configurations provide.
it's better to use implementation or api rather compile
just replace compile with implementation, debugCompile with debugImplementation, testCompile with testImplementation and androidtestcompile with androidTestImplementation
For example: Instead of this
compile 'com.android.support:appcompat-v7:26.0.2'
compile 'com.android.support:support-v4:26.1.0'
compile 'com.github.bumptech.glide:glide:4.0.0'
use like this
implementation 'com.android.support:appcompat-v7:26.0.2'
implementation 'com.android.support:support-v4:26.1.0'
implementation 'com.github.bumptech.glide:glide:4.0.0'
After that
Hope it will helps !
Deleting .gradle
as suggested by Suragch wasn't enough for me. Additionally, I had to perform a Build > Clean Project
.
Note that, in order to see .gradle
, you need to switch to the "Project" view in the navigator on the top left:
I find out the reason of this problem for my project. I was added one dependency twice in build.gradle. One time by adding dependency and one time again by adding jar dependency:
compile 'org.achartengine:achartengine:1.2.0'
...
implementation files('../achartengine-1.2.0.jar')
after remove the first line problem solved.
One of the possibilities is: the presence of the same library but with different versions in the dependencies.
I had this problem with the following lines in gradle file:
compile fileTree(include: ['*.jar'], dir: 'libs')
compile 'com.google.code.gson:gson:2.8.2'
The gson library was in my libs directory but with a previous version.
I deleted the gson-2.3.1.jar
from the libs directory and everything is back to normal.
In my case it was gson-2.8.1.jar which I have added to libs folder of the project. But the reference was already there by SDK. So it was not necesary to add gson-2.8.1.jar to libs folder.
When I took it out th gson-2.8.1.jar project compiles without this wiered error.
So try to revise libs folder and dependencies.
I encountered the same problem and found the real reason for my case. Previously, I also tried all the previous answers again, but it did not solve the problem. I have two module in my wear app project, and the build.gradle as follows:
wear module's build.gradle:
implementation project(':common')
implementation files('libs/farmer-motion-1.0.jar')
common module's build.gradle:
implementation files('libs/farmer-motion-1.0.jar')
Before upgrade to gradle 3.x, 'implementation' are all 'compile'.
I run gradlew with --stacktrace option to get the stack trace, you can just click this on gradle console window when this problem arises. And found that dependency to the jar package repeated:
Caused by: com.android.dex.DexException: Multiple dex files define Lcom/farmer/motion/common/data/pojo/SportSummary$2;
Class SportSummary in the farmer-motion-1.0.jar package, after read the official migration guide, i changed my build.gradle to follows:
wear module's build.gradle:
implementation project(':common')
// delete dependency implementation files('libs/farmer-motion-1.0.jar')
common module的build.gradle:
api files('libs/farmer-motion-1.0.jar') // change implementation to api
Now wear module will has the dependency of farmer-motion-1.0.jar export by common module. If there has no dependency on jar package during runtime, 'implementation' dependency of jar package can also be change to 'compileOnly'.