I just start using Android Studio for a week and it works great for me, but when I started Android Studio today I get the error: 'error: duplicate class: mypackage.R'. I saw this error before when I used Eclipse so I tried to rebuild the project a few times and restarting Android Studio, this didn't help.
After reading some Stackoverflow questions I tried to deleted R.java and rebuild again, now I don't get any error while rebuilding. The only problem is that Android Studio cannot resolve R, so every line which uses R gets an error (project builds and run).
I also tried to delete all the R.class files but this doesn't help either. I checked if some class imports android.R, but they all don't, they just import 'mypackage.R'. I even deleted all my files and checked out a older version of my project but I still have the same problem.
Edit:
If I don't delete R.java the compiler doesn't give any error. Just when I try to build I get a lot of errors like: 'error: cannot find symbol variable button_login'. If I search the R.java file for 'button_login' I just find it. I did this with multiple errors.
Edit2:
When I deleted all the libaries the project now builds. But the problem is that I need those libaries (HTTPComponents). I added them from maven (File --> Project Structure --> Libaries --> +-sign') and added them to my settings.graddle:
buildscript {
repositories {
maven { url 'http://repo1.maven.org/maven2' }
}
dependencies {
classpath 'com.android.tools.build:gradle:0.4'
}
}
apply plugin: 'android'
dependencies {
compile files('libs/android-support-v4.jar')
compile group: 'org.apache.httpcomponents', name: 'httpclient', version: '4.2.5'
compile group: 'org.apache.httpcomponents', name: 'httpmime', version: '4.2.5'
//compile 'org.apache.httpcomponents-httpclient:4.2.5' doesn't work either
//compile 'org.apache.httpcomponents-httpmime:4.2.5' doesn't work either
}
android {
compileSdkVersion 17
buildToolsVersion "17.0.0"
defaultConfig {
minSdkVersion 15
targetSdkVersion 16
}
}
When I run gradlew.bat --stacktrace --info assemble I get errors that Gradle is unable to find the libaries from the maven repository. I checked the repository but they are available. http://search.maven.org/#browse%7C1628757896
Unfortunately I run into this as well, sometimes frequently, mostly happens when I put my computer to sleep and back on while Eclipse is on. Sometimes recompiling and validating the project works.
I did find this solution online somewhere, lost the link and do not claim credits for this:
Disable auto build, and clean the project then
Right click your project -> properties -> Java Build Path -> Source -> Add Folder -> add gen and src
Then compile
If that doesn't work, try to delete the gen folder and do that process
Let me know.
Delete the Build folder generated by Android Studio automatically!
Problem is simple usually. You have fresh instal of studio? So you just fogot add SDK support for those version Android in wich try to compile project. Android Studio can`t generate R file. Start SDK manager, install all missing SDK version and rebuld project.
Another problem can be if you use 64bit OS. You ned to install 32 bit lib, because aapt can`t work with 64bit libs.
in Ubuntu install ia32-libs
Fedora described here
in other distr find libs in google (just google:ia32-libs for "mydistr"), i cant describe all of them ;)
P.S. sorry for my English ;)
Delete all class file in your_package_name(androisTest) folder only keep ApplicationTest file.
If you are using some library from which you are getting this error, just delete the build folder under your app source and rebuild the project. I was using OpenCV library for which I w as getting this error and that got resolved by deleting the build folder and rebuilding the project.
Delete all generated code inside "gen" folder.
Uncheck Project->Build Automatically in eclipse.
compile android source once again.
Error will be removed, worked for me.
This still happens sometimes in Android Studio, but a simple Build / Clean Project followed by a Build / Rebuild Project takes care of it.
I have not had this problem for a long time until today.
Error:(10, 14) java: duplicate class: com.domain.name.R
After 2 hours of wasting time on the project and getting this error,
Finally I removed the .idea, gen and out folders and also iml file.
Then I closed the project and then re-import it using import project of main menu again.
Its working well right now.
Related
I have to create an application that makes extensive use of charts.
Reading the web I chose achartengine that seems to have everything I need.
I downloaded the jar file, I plugged in the libs folder, I selected "add to library" and I lunch the gradlew clean.
Result in the sources where I do the import of org.achartengine.xxxx I always returned the error that fails to resolve symbols .
Do you have suggestions?
Thank you
Andrea
I am able to use this library in my Android Studio project, this topic explains how to add AChartEngine repo to your project.
What I did:
Added following to project-wide build.gradle (one from the project root):
allprojects {
repositories {
...
maven {
url "https://repository-achartengine.forge.cloudbees.com/snapshot/"
}
}
}
For every module that uses the library, add this to its build.gradle (you may put this to the top-level build.gradle if it should be included in all modules):
dependencies {
...
compile group: 'org.achartengine', name: 'achartengine', version: '1.2.0'
}
Now I can use the library in the project, I see the classes in code assist popups and build runs as succeeds.
It seems like the new version (1.2.0) is not available for download anymore in the http://www.achartengine.org/ site. and that's why the gradle/maven method doesn't work (or the snapshot file was removed).
I succeeded using and adding it to my project by downloading the jar file from here:
https://github.com/ddanny/achartengine/files/460139/achartengine-1.2.0.zip
I created a new layout file in the appropriate resource folder. After syncing, when I try to reference the layout file, i.e. R.layout.activity_test, R is an "unresolved symbol". When I try to build in AS it fails.
The interesting thing is that if I manually import the R file and use it in code, when I try to build on command line, it works. The other thing is when I try to access the layout file using R in a Java file, that also works. So I know R.java is being generated.
I tried creating a totally new project, and R is accessible in Kotlin files.
What is the problem here?
Things I have tried:
Cleaned then built
Invalidated Caches / Restart
Blow away .gradle folders and recreate indexes
Other info:
AS v3.0.1
Tried both Kotlin v1.1.2-4 and v1.1.60
Gradle v4.2.1
Gradle Plugin v3.0.0
Invalidate Caches/Restart worked for me.
Runtime JAR files in the classpath should have the same version. These files were found in the classpath:
C:/Users/R3ZA/.gradle/caches/modules-2/files-2.1/me.eugeniomarletti.kotlin.metadata/kotlin-compiler-lite/1.0.3-k-1.2.40/a16e967c276379eaf6e1fa03af77664f003db947/kotlin-compiler-lite-1.0.3-k-1.2.40.jar (version 1.2)
C:/Users/R3ZA/.gradle/caches/modules-2/files-2.1/org.jetbrains.kotlin/kotlin-stdlib/1.3.20/eb2a232734e09fcd1b958a5c7520a93c6de38b32/kotlin-stdlib-1.3.20.jar (version 1.3)
C:/Users/R3ZA/.gradle/caches/modules-2/files-2.1/org.jetbrains.kotlin/kotlin-stdlib-common/1.3.20/7d7934e26ce34da1a0a8d00e38038d7cf3375e89/kotlin-stdlib-common-1.3.20.jar (version 1.3)
Add the following under android section in your application module:
android {
...
sourceSets {
main.java.srcDirs += 'src/main/kotlin'
}
}
This lets Android Studio know that the kotlin directory is a source
root, so when the project model is loaded into the IDE it will be
properly recognized. Alternatively, you can put Kotlin classes in the
Java source directory, typically located in src/main/java.
https://kotlinlang.org/docs/reference/using-gradle.html#android-studio
If you have a warning in your project please fix it.
in my case my Gradle version had a version Compile warning.
the App runs fine but the R class was not recognized, so I change the gradle version and fix the warnings and all works well.
Update 2 This has been fixed in Android Studio 1.2 Beta 3
Update: This has reportedly been fixed in an upcoming release of Android Studio.
In Android Studio 1.2 Beta 2 I started getting the following warnings when syncing Gradle.
Failed to set up dependencies
Warning:Unable to find module with Gradle path ':Library1'. Linking to library 'Library1-unspecified' instead.
Warning:Unable to find module with Gradle path ':Library2'. Linking to library 'Library2-unspecified' instead.
I've noticed that jumping to a declaration declared in one of the library modules pulls up the Decompiler instead of just going to the actual source in the library module.
In my Android Studio Project I have the following modules:
- App
- Library1
- Library2
Module: App build.gradle snippet:
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile project(':Library1')
compile project(':Library2')
}
settings.gradle file:
include ':App'
include ':Library1'
include ':Library2'
project(':Library1').projectDir = new File(settingsDir, '../library1/lib')
project(':Library2').projectDir = new File(settingsDir, '../Library2/lib')
I faced this with Android Studio 2.2.3. The problem was with the .iml file that was causing the problem.
After importing the module folder into the project directory and adding the changes to include module in settings.gradle, delete the .iml file from the module folder and do a Gradle Sync. Then right click on any module in the Project Window and click on "Configure Project Subset...", if the imported module is not checked, check it and Android Studio should do a Gradle Sync. By then the imported module will appear in the Project Window and will have a .iml file regenerated that is does not cause any issues.
delete the .iml file under the error module.
restart Android studio
Right click project, Select "Configure Project Subset ..." and select your module, rebuild your project.
I met the same problem on AS 2.0 preview,
and I fixed it by following steps:
1.Rename the module.
2.Change the names in app/build.gradle and setting.gradle.
3.Start gradle sync.
I don't know why but it works on my issue.
Check in settings. of your app.
Down there is the field "Load/Unload Modules"
Your module might be unloaded, that's why Android Studio ignores it even if you specify it in Gradle.
At least that was the problem for me.
If you are using React-native>60, then you should run npx jetify on root of your project before doing Gradle sync.
For me the following worked in Android Studio 3.5.3
First of all, check if the path is correct in your Gradle settings.
If the path is correct then invalidate caches & restart by navigating to the top 'File' menu
It is a known bug introduced in 1.2 Beta 2.
See This issue on the Android issue tracker. Fix should be out within hours.
I had this problem and solved it by clicking on
File> Ivalidate cache / Restart...
as shown below:
Problem:
This problem can also occur when you change the path to the module.
settings.gradle
include ':app', ':filechooserlibrary'
project(':filechooserlibrary').projectDir = new File('../../repos-github/file-chooser/file-chooser-library/filechooserlibrary')
I changed the path to '../../github/file-chooser/file-chooser-library/filechooserlibrary'
The old path did not exist any more. But then, instead of accepting the new path, Android Studio recreated the old path structure thus referring to an empty directory.
Solution:
So, I deleted this obsolete path structure and restarted Android Studio, after deleting the .iml file (I don't know if this is necessary, but it cannot do harm). Then I reimported the Gradle project and it worked.
Try using an updated version of NDK.
I faced the same issue.
I was using NDK version r17c. Issue solve after using r21e.
Android Studio Version: 4.1.3
OS: Ubuntu 18.04.5
I have to create an application that makes extensive use of charts.
Reading the web I chose achartengine that seems to have everything I need.
I downloaded the jar file, I plugged in the libs folder, I selected "add to library" and I lunch the gradlew clean.
Result in the sources where I do the import of org.achartengine.xxxx I always returned the error that fails to resolve symbols .
Do you have suggestions?
Thank you
Andrea
I am able to use this library in my Android Studio project, this topic explains how to add AChartEngine repo to your project.
What I did:
Added following to project-wide build.gradle (one from the project root):
allprojects {
repositories {
...
maven {
url "https://repository-achartengine.forge.cloudbees.com/snapshot/"
}
}
}
For every module that uses the library, add this to its build.gradle (you may put this to the top-level build.gradle if it should be included in all modules):
dependencies {
...
compile group: 'org.achartengine', name: 'achartengine', version: '1.2.0'
}
Now I can use the library in the project, I see the classes in code assist popups and build runs as succeeds.
It seems like the new version (1.2.0) is not available for download anymore in the http://www.achartengine.org/ site. and that's why the gradle/maven method doesn't work (or the snapshot file was removed).
I succeeded using and adding it to my project by downloading the jar file from here:
https://github.com/ddanny/achartengine/files/460139/achartengine-1.2.0.zip
I've recently started doing Android development again and I am not yet used to the new gradle build system. Any dependency I add (so far I've tried Joda DateTime and butterknife), it always throws an error NoClassDefFoundError.
Here is what I've done. I'm using IntelliJ.
build.gradle:
compile 'joda-time:joda-time:2.1'
compile 'com.jakewharton:butterknife:4.0.1'
File > Project Structure > Modules > MyModule > Dependencies > Add Library, download from Maven, click export and bump it up the list.
My dependency list now includes a maven module com.jakewharton:butterknife:4.0.1
What am I doing wrong here? My IDE resolves everything fine, but at runtime none of the classes can be resolved.
Side note: My BUILD would not even complete until I added the above line to build.gradle. So I have to add the dependencies in Project > Project Structure AND to the build.gradle?
Also my project structure is:
UITest (parent)
UIBeta (android application)
UILib (android module)
I see the butterknife lib in the UITest\libs folder, shouldn't the children be able to find this?
Well I was going to delete this but maybe it will help someone else:
My gradle clean was broken because some aar was locked and it could not delete it, I had to close out IntelliJ, rename the aar (appcompat7 I think it was), then restart. I might not even have had to rename the file as I'm guessing the lock was released upon closing.
After restarting my clean worked, upon next run no more error.