Android source build: duplicate class - android

While building Android source code I am getting this error:
out/target/common/obj/APPS/SystemUI_intermediates/src/com/android/systemui/R.java:10: duplicate class: com.android.systemui.R
Even if I execute the rm command to remove that file or execute make clean. Why is that, and how do I deal with it?

You probably have 2 R.java files in 2 different directories. You should run a search to locate and delete both of them, then try to rebuild.

One build system can leave generated R.java source file in one directory, while other build system will take it as a regular source file and put generated R.java into another directory.
For example, you can use AOSP building process, but after opening your sources in IntelliJ it breaks, because IntelliJ has put extra R.java under gen/ directory.
Summary: properly clean your output directory and check that your source directories doesn't get extra R.java file. run find . -name R.java in project root directory to see if any reduntant R.java files like in gen dir

It did not help me deleting the duplicated R.java and BuildConfig files because it was always recreating it and showing the above error.
What helped me is understanding why the files where duplicated at the first places. In my case it was because I mistakenly made a loop dependency between my modules in the project. This way when compiler started creating classes for one of the modules it already compiled as a dependency it showed the error.
Removing the unneeded dependency and recompiling the project fixed the problem.
P.S.
The reason I did not find the dependency problem right away is because the Android studio I am currently using (0.6.1) has a bug where sometimes the project settings view gets buggy and shows modules that were already removed or does not show modules that are currently there in the dependency list. Restarting the Android studio fixes the problem, so I suggest restarting before applying the above fix.

check whether you have change package name in the manifest file or try to delete the R.java file and then build it again.

I got the same error while deploying Android application from QT.
I've opened the build directory like
"C:\Myproject\src\builds\build-helloworldandroid-Android_for_armeabi_v7a_Clang_Qt_5_12_3_for_Android_ARMv7-Release"
and I deleted all of the files and compiled again.
Errors disappeared and successfully ran the application.

If you tried deleting your project files and directories in the past, you probably did not delete the classes that gave you duplicate class errors, albeit unintentionally.
Build > Clean Project fixed this issue for me.

Related

"DexException: Multiple dex files define" using Weibo SDK [duplicate]

Since updating to ADT 14 I can no longer build my project. It was building fine prior to updating.
The error:
[2011-10-23 16:23:29 - Dex Loader] Unable to execute dex: Multiple dex files define Lcom/myapp/R$array;
[2011-10-23 16:23:29 - myProj] Conversion to Dalvik format failed: Unable to execute dex: Multiple dex files define Lcom/myapp/R$array;
Similar issues have been reported and I have tried the suggestions there including
Restarting Eclipse.
Cleaning the project and rebuild - Disable "Project->Build Automatically" option, then "Clean" and "Build" project, then try to run. reset "Build Automatically" option to On
Re-installing the Android Developer Tools
Re-installing Eclipse (updated to the latest version 3.7.1)
Created a new project importing from the file system
Created a new project from subversion.
I had the same problem, quite weird because it was happening only when using Eclipse (but it was OK with Ant).
This is how I fixed it:
Right click on the Project Name
Select Build Path -> Configure Build Path
In Java Build Path, go to the tab Order and Export
Uncheck your .jar library
Only sometimes:
In Order and Export tab I did not have any jar library there, so I have unchecked Android Private Libraries item. Now my project is running.
My problem was resolved after cleaning up some directories and files left over from the previous versions of the tools. ADT Rev 14 changes where binaries are stored. I deleted the entire bin directory, restarted Eclipse and cleaned the build and forced a rebuild. That seemed to do the trick initially but the problem came back after the next run.
I finally discovered that my bin directory was included in the project build path. I excluded bin from the build path and repeated the steps above. This resolved my problem.
[Solved for me]
Eclipse project properties->Java build path->Order and export
Uncheck Android private libraries.
None of the above helped.
It was a simple problem in the end.
I had a project which uses the FacebookSDK and ViewPagerIndicator as library projects.
All were built on Android API 16 and those two projects used the android support library vX (X not being 16!)
I added an external JAR to both those projects and pointed it to \extras\android\v4...
And also removed the v4 jar I had in their libs folders.
Clean all projects and re-build.
Voilla!
The exact error I was receiving: Unable to execute dex: Multiple dex files define Landroid/support/v4/view/PagerAdapter; Conversion to Dalvik format failed: Unable to execute dex: Multiple dex files define Landroid/support/v4/view/PagerAdapter;
This problem was happening me, I had an external .jar in my libs folder called gson-2.2.2.jar but for some reason there were two of them, gson-2.2.2.jar and gson-2.2.2.jar(1), I simply deleted the latter and my project built fine again.
Close eclipse.
Delete bin folder inside your project folder.
Start eclipse and clean your project.
Now run and the problem should be gone
As others have mentioned, this occurs when you have multiple copies of the same class in your build path - including bin/ in your classpath is one way to guarantee this problem.
For me, this occurred when I had added android-support-v4.jar to my libs/ folder, and somehow eclipse added a second copy to bin/classes/android-support-v4.jar.
Deleting the extra copy in bin/classes solved the problem - unsure why Eclipse made a copy there.
You can test for this with
grep -r YourOffendingClassName YourApp | grep jar
For me, I just right click on project -> Build path -> configure build path -> Libraries -> remove dependency
after it works.
This error can happen if you have two jars that contains the same class names, e.g. I had two library: jsr311-api-1.1.1.jar, and jersey-core-1.17.1.jar, both containing the class javax.ws.rs.ApplicationPath. I removed jsr311-api-1.1.1.jar and it worked fine.
I was getting this error after adding the facebooksdk.jar to a project that already had dependencies on the android-support-v4.jar. Since the facebooksdk.jar already includes its own android-support-v4.jar there were conflicts. Removing the earlier android-support-v4.jar from the projects Properties / Java Build Path / Libraries resolved the issue for me.
Go to Project/properties and Java Build Path and unchecked the Android Private Libraries.
Done
I removed Android dependencies from build path and it worked.
Edit: ignore that. I had same jar in my maven dependencies and libs folder. I removed the one at the lib folder.
You have probably installed r14, this error may have been caused due to the platform tools update, you have to re-install your sdk
For me this problem only exists as long as there are Android library projects involved in my project. So when I remove all the libraries and do as you said I can run my app again.
If there are libraries involved even the bin-removal-trick trick won' work.
I don't get why this bug first appeared today since I'm using ADT 14 for several days now. Well there were other bugs that kept me happy though.
Deleting the bin folder was not enough, I also deleted the gen folder. Then after two rebuilds the dex error message was gone.
Select the project in Project Explorer, right-click and select Properties -> Java Build Path -> Source -> Check the box for Allow output folders for source folders
I was basically facing the same issue.
I deleted the BIN folder, then removed unused jar files for Order and Import from eclipse.
IT WORKED after that
I'm late to this party, but adding my own experience so I can find it again later :)
I ran into this problem after upgrading the android sdk and eclipse ad-ins. No upgrade goes unpunished!
The problem for me was related to library projects, my app references both standard java projects and android library projects. I noticed the Java Build Path settings were including the android library projects src and res folders in the Source list (upvotes to everyone that mention bin in source being issue, src and res was also an issue.)
So the solution was:
Remove all referenced Android libraries source and project references from the Java Build Path section of the settings in both Source list and Project list
Make sure pure java dependencies are listed in Project list, and Checked in the Order and Export tab so the classes are included in the apk
Make sure all Android library dependencies are listed on the Android section of project properties, in the library section below the checked SDK versions.
It was along way to piece all that together from the other solutions! Phew!
I ran into this when I upgraded from adt 14 to 15 and to get it to work I ended up just deleting the .eclipse folder (along with my settings) and re-installing the adt 15.
After reading Terrys response about deleting the bin directory and Larrys about the the location of the ANT directory:
I moved the files located in my projects BIN directory to the BIN/CLASSES and im up and running.
Edit 1
Then failed on second run...doh
Edit 2
So closed Eclipse moved files back to original location and its all working... um what?
I don't pretend to know why this worked. Will update if any changes.
Edit 3
I have noted from my backups that there were indeed duplicate files in the BIN directory and BIN/CLASSES.
So the answer is: don't have files in both locations. At least for me that's what worked.
Modify your eclipse.ini file and set the maximum memory parameter to
-Xmx1024m
Then restart your computer.
It worked for me.
found a solution i believe??
[2013-04-28 23:56:09 - Dex Loader] Unable to execute dex: Multiple dex files define Lcom/coremedia/iso/AbstractBoxParser$1;
Where it says : "Lcom/coremedia/iso/AbstractBoxParser$1" that just happen to be the location of the library I imported that was causing the issue. Looked for com.codemedia.iso.AbstractBoxParser$1.class and .AbstractBoxParser.class.... took that jar, unpackaged it, removed both of those files, then repackaged as a .zip, added to library, cleaned and worked! no more conflict for me! (also no updates or additional downloads)
I had two different versions of Cordova .jar-files in my libs folder, I deleted the one I wasn't even using and it worked right away.
Weird because I didn't notice that before and it worked before and then suddenly stopped working...
The ADT R14 update changes where the classes go to the bin/classes directory (see http://tools.android.com/recent/buildchangesinrevision14). If you are using ANT, you should change the path for your classes from bin to bin/classes. This worked for me.
Solution for me:
BACK UP YOUR CODE!
Navigate to your project workspace (not your project) and run the following commands:
dev1:workspace$ cd ~/Documents/workspace/.metadata/.plugins/
dev1:workspace$ rm -rf org.eclipse.core.resources
Navigate to your Eclipse directory and type this command:
dev1:eclipse$ ./eclipse clear
Eclipse will start with an empty workspace - don't worry your projects are still there.
Simple create new project from existing resource and things should be gravy.
The exact error I was receiving:
[2012-02-07 14:15:53 - Dex Loader] Unable to execute dex: Multiple dex files define Landroid/support/v4/view/PagerAdapter;
[2012-02-07 14:15:53 - ProjectCloud] Conversion to Dalvik format failed: Unable to execute dex: Multiple dex files define Landroid/support/v4/view/PagerAdapter;
I have several library projects with the same package name specified in the AndroidManifest (so no duplicate field names are generated by R.java). I had to remove any permissions and activities from the AndroidManifest.xml for all library projects to remove the error so Manifest.java wasn't created multiple times. Hopefully this can help someone.
After trying all the other suggestions with no luck, I deleted all the contents of my projects 'bin' directory, then ran eclipse again and it worked.
I converted a non-library project to a library project, but it had a previously built jar file in the libs folder. Removing this jar file caused this error to go away.
I was facing the same issue then i saw while pushing my app some jar files which were loaded twice hence multiple dex error .Just go to your project properties -> Java Build Path and try unchecking jar which is being loaded twice.
[Solved for me]
by removing the duplicate library "JAR file" then remove BuildConfig.java file, Clean project and its work.

Unable to execute dex: Multiple dex files define in Android [duplicate]

Since updating to ADT 14 I can no longer build my project. It was building fine prior to updating.
The error:
[2011-10-23 16:23:29 - Dex Loader] Unable to execute dex: Multiple dex files define Lcom/myapp/R$array;
[2011-10-23 16:23:29 - myProj] Conversion to Dalvik format failed: Unable to execute dex: Multiple dex files define Lcom/myapp/R$array;
Similar issues have been reported and I have tried the suggestions there including
Restarting Eclipse.
Cleaning the project and rebuild - Disable "Project->Build Automatically" option, then "Clean" and "Build" project, then try to run. reset "Build Automatically" option to On
Re-installing the Android Developer Tools
Re-installing Eclipse (updated to the latest version 3.7.1)
Created a new project importing from the file system
Created a new project from subversion.
I had the same problem, quite weird because it was happening only when using Eclipse (but it was OK with Ant).
This is how I fixed it:
Right click on the Project Name
Select Build Path -> Configure Build Path
In Java Build Path, go to the tab Order and Export
Uncheck your .jar library
Only sometimes:
In Order and Export tab I did not have any jar library there, so I have unchecked Android Private Libraries item. Now my project is running.
My problem was resolved after cleaning up some directories and files left over from the previous versions of the tools. ADT Rev 14 changes where binaries are stored. I deleted the entire bin directory, restarted Eclipse and cleaned the build and forced a rebuild. That seemed to do the trick initially but the problem came back after the next run.
I finally discovered that my bin directory was included in the project build path. I excluded bin from the build path and repeated the steps above. This resolved my problem.
[Solved for me]
Eclipse project properties->Java build path->Order and export
Uncheck Android private libraries.
None of the above helped.
It was a simple problem in the end.
I had a project which uses the FacebookSDK and ViewPagerIndicator as library projects.
All were built on Android API 16 and those two projects used the android support library vX (X not being 16!)
I added an external JAR to both those projects and pointed it to \extras\android\v4...
And also removed the v4 jar I had in their libs folders.
Clean all projects and re-build.
Voilla!
The exact error I was receiving: Unable to execute dex: Multiple dex files define Landroid/support/v4/view/PagerAdapter; Conversion to Dalvik format failed: Unable to execute dex: Multiple dex files define Landroid/support/v4/view/PagerAdapter;
This problem was happening me, I had an external .jar in my libs folder called gson-2.2.2.jar but for some reason there were two of them, gson-2.2.2.jar and gson-2.2.2.jar(1), I simply deleted the latter and my project built fine again.
Close eclipse.
Delete bin folder inside your project folder.
Start eclipse and clean your project.
Now run and the problem should be gone
As others have mentioned, this occurs when you have multiple copies of the same class in your build path - including bin/ in your classpath is one way to guarantee this problem.
For me, this occurred when I had added android-support-v4.jar to my libs/ folder, and somehow eclipse added a second copy to bin/classes/android-support-v4.jar.
Deleting the extra copy in bin/classes solved the problem - unsure why Eclipse made a copy there.
You can test for this with
grep -r YourOffendingClassName YourApp | grep jar
For me, I just right click on project -> Build path -> configure build path -> Libraries -> remove dependency
after it works.
This error can happen if you have two jars that contains the same class names, e.g. I had two library: jsr311-api-1.1.1.jar, and jersey-core-1.17.1.jar, both containing the class javax.ws.rs.ApplicationPath. I removed jsr311-api-1.1.1.jar and it worked fine.
I was getting this error after adding the facebooksdk.jar to a project that already had dependencies on the android-support-v4.jar. Since the facebooksdk.jar already includes its own android-support-v4.jar there were conflicts. Removing the earlier android-support-v4.jar from the projects Properties / Java Build Path / Libraries resolved the issue for me.
Go to Project/properties and Java Build Path and unchecked the Android Private Libraries.
Done
I removed Android dependencies from build path and it worked.
Edit: ignore that. I had same jar in my maven dependencies and libs folder. I removed the one at the lib folder.
You have probably installed r14, this error may have been caused due to the platform tools update, you have to re-install your sdk
For me this problem only exists as long as there are Android library projects involved in my project. So when I remove all the libraries and do as you said I can run my app again.
If there are libraries involved even the bin-removal-trick trick won' work.
I don't get why this bug first appeared today since I'm using ADT 14 for several days now. Well there were other bugs that kept me happy though.
Deleting the bin folder was not enough, I also deleted the gen folder. Then after two rebuilds the dex error message was gone.
Select the project in Project Explorer, right-click and select Properties -> Java Build Path -> Source -> Check the box for Allow output folders for source folders
I was basically facing the same issue.
I deleted the BIN folder, then removed unused jar files for Order and Import from eclipse.
IT WORKED after that
I'm late to this party, but adding my own experience so I can find it again later :)
I ran into this problem after upgrading the android sdk and eclipse ad-ins. No upgrade goes unpunished!
The problem for me was related to library projects, my app references both standard java projects and android library projects. I noticed the Java Build Path settings were including the android library projects src and res folders in the Source list (upvotes to everyone that mention bin in source being issue, src and res was also an issue.)
So the solution was:
Remove all referenced Android libraries source and project references from the Java Build Path section of the settings in both Source list and Project list
Make sure pure java dependencies are listed in Project list, and Checked in the Order and Export tab so the classes are included in the apk
Make sure all Android library dependencies are listed on the Android section of project properties, in the library section below the checked SDK versions.
It was along way to piece all that together from the other solutions! Phew!
I ran into this when I upgraded from adt 14 to 15 and to get it to work I ended up just deleting the .eclipse folder (along with my settings) and re-installing the adt 15.
After reading Terrys response about deleting the bin directory and Larrys about the the location of the ANT directory:
I moved the files located in my projects BIN directory to the BIN/CLASSES and im up and running.
Edit 1
Then failed on second run...doh
Edit 2
So closed Eclipse moved files back to original location and its all working... um what?
I don't pretend to know why this worked. Will update if any changes.
Edit 3
I have noted from my backups that there were indeed duplicate files in the BIN directory and BIN/CLASSES.
So the answer is: don't have files in both locations. At least for me that's what worked.
Modify your eclipse.ini file and set the maximum memory parameter to
-Xmx1024m
Then restart your computer.
It worked for me.
found a solution i believe??
[2013-04-28 23:56:09 - Dex Loader] Unable to execute dex: Multiple dex files define Lcom/coremedia/iso/AbstractBoxParser$1;
Where it says : "Lcom/coremedia/iso/AbstractBoxParser$1" that just happen to be the location of the library I imported that was causing the issue. Looked for com.codemedia.iso.AbstractBoxParser$1.class and .AbstractBoxParser.class.... took that jar, unpackaged it, removed both of those files, then repackaged as a .zip, added to library, cleaned and worked! no more conflict for me! (also no updates or additional downloads)
I had two different versions of Cordova .jar-files in my libs folder, I deleted the one I wasn't even using and it worked right away.
Weird because I didn't notice that before and it worked before and then suddenly stopped working...
The ADT R14 update changes where the classes go to the bin/classes directory (see http://tools.android.com/recent/buildchangesinrevision14). If you are using ANT, you should change the path for your classes from bin to bin/classes. This worked for me.
Solution for me:
BACK UP YOUR CODE!
Navigate to your project workspace (not your project) and run the following commands:
dev1:workspace$ cd ~/Documents/workspace/.metadata/.plugins/
dev1:workspace$ rm -rf org.eclipse.core.resources
Navigate to your Eclipse directory and type this command:
dev1:eclipse$ ./eclipse clear
Eclipse will start with an empty workspace - don't worry your projects are still there.
Simple create new project from existing resource and things should be gravy.
The exact error I was receiving:
[2012-02-07 14:15:53 - Dex Loader] Unable to execute dex: Multiple dex files define Landroid/support/v4/view/PagerAdapter;
[2012-02-07 14:15:53 - ProjectCloud] Conversion to Dalvik format failed: Unable to execute dex: Multiple dex files define Landroid/support/v4/view/PagerAdapter;
I have several library projects with the same package name specified in the AndroidManifest (so no duplicate field names are generated by R.java). I had to remove any permissions and activities from the AndroidManifest.xml for all library projects to remove the error so Manifest.java wasn't created multiple times. Hopefully this can help someone.
After trying all the other suggestions with no luck, I deleted all the contents of my projects 'bin' directory, then ran eclipse again and it worked.
I converted a non-library project to a library project, but it had a previously built jar file in the libs folder. Removing this jar file caused this error to go away.
I was facing the same issue then i saw while pushing my app some jar files which were loaded twice hence multiple dex error .Just go to your project properties -> Java Build Path and try unchecking jar which is being loaded twice.
[Solved for me]
by removing the duplicate library "JAR file" then remove BuildConfig.java file, Clean project and its work.

Unable to execute dex: Multiple dex files define Lcom/myapp/R$array;

Since updating to ADT 14 I can no longer build my project. It was building fine prior to updating.
The error:
[2011-10-23 16:23:29 - Dex Loader] Unable to execute dex: Multiple dex files define Lcom/myapp/R$array;
[2011-10-23 16:23:29 - myProj] Conversion to Dalvik format failed: Unable to execute dex: Multiple dex files define Lcom/myapp/R$array;
Similar issues have been reported and I have tried the suggestions there including
Restarting Eclipse.
Cleaning the project and rebuild - Disable "Project->Build Automatically" option, then "Clean" and "Build" project, then try to run. reset "Build Automatically" option to On
Re-installing the Android Developer Tools
Re-installing Eclipse (updated to the latest version 3.7.1)
Created a new project importing from the file system
Created a new project from subversion.
I had the same problem, quite weird because it was happening only when using Eclipse (but it was OK with Ant).
This is how I fixed it:
Right click on the Project Name
Select Build Path -> Configure Build Path
In Java Build Path, go to the tab Order and Export
Uncheck your .jar library
Only sometimes:
In Order and Export tab I did not have any jar library there, so I have unchecked Android Private Libraries item. Now my project is running.
My problem was resolved after cleaning up some directories and files left over from the previous versions of the tools. ADT Rev 14 changes where binaries are stored. I deleted the entire bin directory, restarted Eclipse and cleaned the build and forced a rebuild. That seemed to do the trick initially but the problem came back after the next run.
I finally discovered that my bin directory was included in the project build path. I excluded bin from the build path and repeated the steps above. This resolved my problem.
[Solved for me]
Eclipse project properties->Java build path->Order and export
Uncheck Android private libraries.
None of the above helped.
It was a simple problem in the end.
I had a project which uses the FacebookSDK and ViewPagerIndicator as library projects.
All were built on Android API 16 and those two projects used the android support library vX (X not being 16!)
I added an external JAR to both those projects and pointed it to \extras\android\v4...
And also removed the v4 jar I had in their libs folders.
Clean all projects and re-build.
Voilla!
The exact error I was receiving: Unable to execute dex: Multiple dex files define Landroid/support/v4/view/PagerAdapter; Conversion to Dalvik format failed: Unable to execute dex: Multiple dex files define Landroid/support/v4/view/PagerAdapter;
This problem was happening me, I had an external .jar in my libs folder called gson-2.2.2.jar but for some reason there were two of them, gson-2.2.2.jar and gson-2.2.2.jar(1), I simply deleted the latter and my project built fine again.
Close eclipse.
Delete bin folder inside your project folder.
Start eclipse and clean your project.
Now run and the problem should be gone
As others have mentioned, this occurs when you have multiple copies of the same class in your build path - including bin/ in your classpath is one way to guarantee this problem.
For me, this occurred when I had added android-support-v4.jar to my libs/ folder, and somehow eclipse added a second copy to bin/classes/android-support-v4.jar.
Deleting the extra copy in bin/classes solved the problem - unsure why Eclipse made a copy there.
You can test for this with
grep -r YourOffendingClassName YourApp | grep jar
For me, I just right click on project -> Build path -> configure build path -> Libraries -> remove dependency
after it works.
This error can happen if you have two jars that contains the same class names, e.g. I had two library: jsr311-api-1.1.1.jar, and jersey-core-1.17.1.jar, both containing the class javax.ws.rs.ApplicationPath. I removed jsr311-api-1.1.1.jar and it worked fine.
I was getting this error after adding the facebooksdk.jar to a project that already had dependencies on the android-support-v4.jar. Since the facebooksdk.jar already includes its own android-support-v4.jar there were conflicts. Removing the earlier android-support-v4.jar from the projects Properties / Java Build Path / Libraries resolved the issue for me.
Go to Project/properties and Java Build Path and unchecked the Android Private Libraries.
Done
I removed Android dependencies from build path and it worked.
Edit: ignore that. I had same jar in my maven dependencies and libs folder. I removed the one at the lib folder.
You have probably installed r14, this error may have been caused due to the platform tools update, you have to re-install your sdk
For me this problem only exists as long as there are Android library projects involved in my project. So when I remove all the libraries and do as you said I can run my app again.
If there are libraries involved even the bin-removal-trick trick won' work.
I don't get why this bug first appeared today since I'm using ADT 14 for several days now. Well there were other bugs that kept me happy though.
Deleting the bin folder was not enough, I also deleted the gen folder. Then after two rebuilds the dex error message was gone.
Select the project in Project Explorer, right-click and select Properties -> Java Build Path -> Source -> Check the box for Allow output folders for source folders
I was basically facing the same issue.
I deleted the BIN folder, then removed unused jar files for Order and Import from eclipse.
IT WORKED after that
I'm late to this party, but adding my own experience so I can find it again later :)
I ran into this problem after upgrading the android sdk and eclipse ad-ins. No upgrade goes unpunished!
The problem for me was related to library projects, my app references both standard java projects and android library projects. I noticed the Java Build Path settings were including the android library projects src and res folders in the Source list (upvotes to everyone that mention bin in source being issue, src and res was also an issue.)
So the solution was:
Remove all referenced Android libraries source and project references from the Java Build Path section of the settings in both Source list and Project list
Make sure pure java dependencies are listed in Project list, and Checked in the Order and Export tab so the classes are included in the apk
Make sure all Android library dependencies are listed on the Android section of project properties, in the library section below the checked SDK versions.
It was along way to piece all that together from the other solutions! Phew!
I ran into this when I upgraded from adt 14 to 15 and to get it to work I ended up just deleting the .eclipse folder (along with my settings) and re-installing the adt 15.
After reading Terrys response about deleting the bin directory and Larrys about the the location of the ANT directory:
I moved the files located in my projects BIN directory to the BIN/CLASSES and im up and running.
Edit 1
Then failed on second run...doh
Edit 2
So closed Eclipse moved files back to original location and its all working... um what?
I don't pretend to know why this worked. Will update if any changes.
Edit 3
I have noted from my backups that there were indeed duplicate files in the BIN directory and BIN/CLASSES.
So the answer is: don't have files in both locations. At least for me that's what worked.
Modify your eclipse.ini file and set the maximum memory parameter to
-Xmx1024m
Then restart your computer.
It worked for me.
found a solution i believe??
[2013-04-28 23:56:09 - Dex Loader] Unable to execute dex: Multiple dex files define Lcom/coremedia/iso/AbstractBoxParser$1;
Where it says : "Lcom/coremedia/iso/AbstractBoxParser$1" that just happen to be the location of the library I imported that was causing the issue. Looked for com.codemedia.iso.AbstractBoxParser$1.class and .AbstractBoxParser.class.... took that jar, unpackaged it, removed both of those files, then repackaged as a .zip, added to library, cleaned and worked! no more conflict for me! (also no updates or additional downloads)
I had two different versions of Cordova .jar-files in my libs folder, I deleted the one I wasn't even using and it worked right away.
Weird because I didn't notice that before and it worked before and then suddenly stopped working...
The ADT R14 update changes where the classes go to the bin/classes directory (see http://tools.android.com/recent/buildchangesinrevision14). If you are using ANT, you should change the path for your classes from bin to bin/classes. This worked for me.
Solution for me:
BACK UP YOUR CODE!
Navigate to your project workspace (not your project) and run the following commands:
dev1:workspace$ cd ~/Documents/workspace/.metadata/.plugins/
dev1:workspace$ rm -rf org.eclipse.core.resources
Navigate to your Eclipse directory and type this command:
dev1:eclipse$ ./eclipse clear
Eclipse will start with an empty workspace - don't worry your projects are still there.
Simple create new project from existing resource and things should be gravy.
The exact error I was receiving:
[2012-02-07 14:15:53 - Dex Loader] Unable to execute dex: Multiple dex files define Landroid/support/v4/view/PagerAdapter;
[2012-02-07 14:15:53 - ProjectCloud] Conversion to Dalvik format failed: Unable to execute dex: Multiple dex files define Landroid/support/v4/view/PagerAdapter;
I have several library projects with the same package name specified in the AndroidManifest (so no duplicate field names are generated by R.java). I had to remove any permissions and activities from the AndroidManifest.xml for all library projects to remove the error so Manifest.java wasn't created multiple times. Hopefully this can help someone.
After trying all the other suggestions with no luck, I deleted all the contents of my projects 'bin' directory, then ran eclipse again and it worked.
I converted a non-library project to a library project, but it had a previously built jar file in the libs folder. Removing this jar file caused this error to go away.
I was facing the same issue then i saw while pushing my app some jar files which were loaded twice hence multiple dex error .Just go to your project properties -> Java Build Path and try unchecking jar which is being loaded twice.
[Solved for me]
by removing the duplicate library "JAR file" then remove BuildConfig.java file, Clean project and its work.

How to generate R.java

I downloaded few source codes from Google source codes.
I executed them on Eclipse but R.java file is not created and therefore I got many errors saying that R cannot be resolved. There is no main.xml in layout too. Some other XML files are there. How can I execute these programs?
As long as you have a valid Android project, you can use aapt package to generate the R.java from resources. Here's example usage (all should be in one line):
aapt package --non-constant-id -f -m -M <abs_path_to_AndroidManifest.xml>
-S <abs_path_to_res_dir> -I <abs_path_to_platforms_android.jar>
-J <abs_path_to_dir_that_should_contain_gen_R_java)
--generate-dependencies
The above can be made scriptable using ANT by using the aapt target or by simply using an exec target.
Presume you have Android sdk. If you have.. just clean the project. R.java will be autogenerated.
Hi I just faced the same problem. The file R.java is deleted an regenerated each time you clean the project. In my case there were some errors in one of .xml files and no R.java was generated. If you did not have Main.xml that might be the reason. anyway if you fix .xml problems R.java should be generated.
Open Android SDK Manager
Tick Tools that there are 3 packages of Android SDK Tools , delete and install them again.
When they are finished, please refresh your project in Package Explorer.
You will see BuildConfig.java and R.java in /gen
I think you wanna need that I recommend this comment
Enjoy with your building app.
After few hours frustration finally I have decide to remove the red marks from the my file where it was not able to resolve the R.java as it was not actually available in my code. After removing the first red line from my activity file the project builds and generated the R.java automatically.
This is something really freaking thing for me as it goes without any reason and came back with the same thing.
If your build.xml includes the "-resource-src" target (which it will if you include $SDK_DIR/tools/main_rules.xml or lib_rules.xml) you can rebuild it with ant.
For future readers, restart adb then clean.
Correct all errors in the Xml layouts, if the errors is only in the id attribute, change to other name an save, then type the original values, this solution works for me.
I encountered this issue after adding a jpg file with a numeric file name into my drawable folder. I was getting a compilation error, " expected on line y" when trying to rebuild the project after cleaning it. You may want to check that you do not have a similar issue. Although I encountered this while using Android Studio, I am sure it would affect Eclipse as well.
Cleaning the project, delete the R.java and regenerate it.
If you have an error anywhere in your /res file (the resources) , the R will not be generated usually.
It could be an error in the name of a picture , or anything ...
fix your errors before.
good luck ;)
I have encountered similar problem and i changed the workspace folder and all errors disappeared. It's sort of simple solution but it works.

Developing for Android in Eclipse: R.java not regenerating

I've found out that my R.java is never updated, so it doesn't contain information about my new resources, so I decided to delete it and thought that Eclipse would generate a new one. But that didn't happen, and I don't have R.java now. How can I regenerate one?
I'm using Windows 7.
From one of the comments: "Doing Project -> Clean is what caused the problem for me. Cleaning deletes R.java...and for whatever reason the plugin is not regenerating the file."
I found this happening to me with a broken layout and everything blows up. Relax, it's like that old mistake when you first learned programming C where you forget one semicolon and it generates a hundred errors. Many panic, press all the buttons, and makes things worse.
Solution
Make sure that anything the R. links to is not broken. Fix all errors in your XML files. If anything in the ADKs are broken, R will not regenerate.
If you somehow hit something and created import android.R in your activity, remove it.
Run Project -> Clean. This will delete and regenerate R and BuildConfig.
Make sure Project -> Build Automatically is ticked. If not, build it manually via Menu -> Project -> Build Project .
Wait a few seconds for the errors to disappear.
If it doesn't work, delete everything inside the /gen/ folder
If it still doesn't work, try right-clicking your project -> Android Tools -> Fix Project Properties.
Check your *.properties files (in the root folder of your app folder) and make sure that the links in there are not broken.
Right-click your project > properties > Android. Look at the Project Build Target and Library sections on the right side of the page. Your Build Target should match the target in your AndroidManifest.xml. So if it's set to target 17 in AndroidManifest, make sure that the Target Name is Android 4.2. If your Library has an X under the reference, remove and re-add the library until there's a green tick. This might happen if you've moved a few files and folders around.
What to do if R doesn't regenerate
This usually happens when you have a broken XML file.
Check errors inside your XML files, mainly within the /res/ folder
Common places are /layout/ and /values/, especially if you've changed one of them recently
Check AndroidManifest.xml. I find that often I change a string and forget to change the string name from AndroidManifest.xml.
Check that Android SDK Build-tools is installed. Window -> Android SDK Manager -> Tools -> Android SDK Build-tools
Make sure when you update the Android SDK Tools, you also update the Android SDK Platform-tools and Android ADK Build-tools. Build fails silently if they don't match.
If you can't find the issue, right click /gen/ -> Restore from local history... -> tick R.java -> click Restore. Even if it doesn't solve the problem, it will clear out the extra errors to make the problem easier to find.
This site suggests:
if you run a clean on the project it should regenerate all the generated Java files, namely R.
...and...
In Eclipse, under the Project menu, is an option build automatically.
That would help you build the R.java file everytime modifications are
made. The Clean... option is also there under Project.
This site suggests another solution.
I had the same issue. When I checked it out I found that the name of the XML resource under layout was not having the correct naming convention. It had some capital letters. So I renamed it to make all letters lowercase and the magic worked.
One reason the R.class can go missing suddenly is when there are errors in you XML files. For instance, when you add an XML file with uppercase letters in the name like myCoolLayout.xml which is not allowed. Or when you have references that don't point to existing files, etc.
In Eclipse, simply use Project --> clean to clean the project. The
R.java is going to be automaticly (re)-created.
If for some reason that dosn't work: Make sure your layout.xml files don't contains errors. Eclipse seems to be a bit buggy here: sometimes it doesn't mark the errors within the XML nor the package explorer. In such a case: Take a look at the "console" or "problems" view after using "clean". All errors should be displayed there. Fix them and redo a clean.
NOTE: It is NOT neccessary to fix the errors you get because of a missing R file! Just fix the XML files and other project errors and use clean!
Quick fix:
The package name in the manifest needs to be the same as the one in the /src folder, the /gen folder package will be automatically reproduced.
Detailed observation:
Observe the name of package in the /gen folder. In my case it was different than the one in the /src folder.
The package referenced in the manifest was that of the /gen folder.
I attempted to add a package with the name of the /src folder to the /gen folder too see what would've happened, but this did not solve the issue. I proceeded then to remove the package name that was not the same as the package name of the /src folder. This package with the name that did not correspond to the /src folder was recreated as soon as I removed it.
Since the package reference in the manifest corresponded to the one that was being senselessly recreated and that did not correspond with the package in the /src folder, this prompted to rename package = "oldPackage" with the package = "srcFolderPackage".
I had the same issue, and I finally found the problem: In the strings.xml, I did not keep the line <string name="app_name">program-name</string> which is present by default when creating a new Android project. I thought it was only used for the program HelloWord, which is the original program.
However, the AndroidManifest.xml refers to this value, hence:
=> A compile error;
=> the R.java isn't updated;
=> ID are not recognized...
Android has added in SDK build tool ADT 22 for the building mechanism. You just need to do the following steps.
Update Android SDK Tool
Update Android SDK Platform Tool
Update Android SDK Build Tool
Add the path of your build tool to the path variable. (path up to---- YOUR DIRECTORY-PATH\android-sdk\build-tools)
This will solve the issue.
If your R.java isn't getting generated, one of the solutions is to delete the layout file named "blabla.out.xml".
After deleting this file, try cleaning the project from menu Project -> Clean.
As a generalization of Glaux's answer, if you have any errors in the res directory, then R.java may not generate - even if you clean and rebuild. Resolve those errors first.
As an example: when you add an image file of say, "myimage-2.jpg", the system will consider this an error, since file names are limited to alphanumeric values. Do a refresh on your 'res' directory after adding any files and watch the output in your console window for any file name warnings.
If your OS is Ubuntu, I can provide some suggestion:
Install or upgrade ia32-lib:
sudo apt-get upgrade ia32-libs
Check if you have the right permission on the aapt folder:
cd ANDROID/adt-bundle-linux-x86_64-20130522/sdk/build-tools/android-4.2.2
chmod 777 aapt
Start Eclipse:
sudo eclipse
Run Project -> Clean in Eclipse
You 100% have an error in an XML-file, but the XML verification does not show you the error. This is the reason why you need to check your XML files first!
It is ALWAYS helpful to take a look at the Problems Tab in Eclipse. In my case, I was getting a "android unable to resolve target 'android-8'" error message that kept the R.java from being generated. So, I corrected the imported target to the one I was using in the default.properties file, then I performed a clean via Projects->Clean and voila! R.java is automatically generated! Hope it helps!
Cleaning project, closing Eclipse, re-opening it and launching my project finally made my R.java to reappear... Hope it helps
Make sure you are not importing
android.R;
R.java will never be generated if there are any errors in the res folder. For example, in the drawable subfolder there are two files which have the same name, one is icon.png and the other is icon.html.
You can see some error in the Eclipse console log window which is saying "Resource entry icon is already defined.". After deleting icon.html, you can clean or just delete the gen folder. You will find that R.java is created.
I've found that any file that has capital letters in the res folder will create this error. This happened to me with a PNG file I added and forgot about.
After reading through many posts and YouTube videos, I found that each of us have R.java missing for different reasons.
Here's how I fixed this in Eclipse:
Create R.java in gen folder manually and save.
After that go to Project and click "Clean"
The following message will display and your file will automatically be rewritten:
R.java was modified manually! Reverting to generated version!
For me, I had linked v7 appcompat twice. Anyhow, in Eclipse, right click the project name in Package Explorer or Navigator, go to Properties, Android, and uncheck any duplicates in the Library section. You may need to Build --> Clean afterwards.
There's obviously no one final answer to this, but here's another one I don't see here already:
I've had R.java disappear after (attempting) a Team Synchronize, and there were conflict resolution files in the project (i.e., thingy.xml.mine,thingy.xml.r35, etc.). Deleting them/resolving the conflicts regenerated R.
I had this problem. Accidentally I deleted this
xmlns:tools="http://schemas.android.com/tools"
which started causing build errors all over the project in my XML files as well as my Java files. As soon as I retyped what I deleted, it worked again :)
OK so it's clear that there can be a lot of causes for this problem. If you're on a 64 bit linux machine and you are just setting up the ADT for the first time, you may get this problem where R is not automatically generating. Check the console tab and you may see an error similar to:
'No such file or directory' while attempting to get adb version from '/home/patrick/code/android-sdks/platform-tools/adb'
If that's the case you need to install ia32-libs, using something like:
sudo apt-get install ia32-libs
See here for details: Android adb not found
I've came across this problem a few times. I found that if I didn't import the package R through my application's name, for example, if my application had the package name example.test then I found that I had to import example.test.R in order to access any of the resources.
If this wasn't imported then the resources that where getting returned were the default resources with none of my own included.
With that said if you find that you are only getting a list of default resources then just check to make sure that you're importing application_package_name.R and not android.R.
My problem was that appcompat was not in the same directory as my project.
I found this out when compiling my app with Ant.
Also make sure that you have the latest version of the ADT plugin, and open the Android SDK manager to update all SDK tools to the latest version. Check for updates in Eclipse itself as well. Non-matching versions caused the problem for me.
My problem was inside a menu file.
The compiler doesn't seem to warn you if strings which do not exist inside strings.xml are referenced in menu files. Check if your items in your menu XML files reference any strings which do not exist in your strings.xml. Usually in android:title.
For me, this error was caused when I tried to duplicate an existing res/menu instead of creating one with the wizard.
All of these answers could not work if you use Maven. The solution for me was to add
<genDirectory>${project.basedir}/gen</genDirectory>
to the configuration section of android-maven-plugin.
I found a solution why R.class is not made by Eclipse after making it again - 2 clean, build, etc.
The problem is here in strings.xml:
<string name="hello">Hello World, HelloAutoComplete!</string>
<string name="app_name">HelloAutoComplete</string>
These are by default created by Eclipse when you create projects.
Definitely you are changing the strings.xml for your own requirement. Sometimes you clear the string.xmls these two lines from your code:
It is making a problem in the AndroidManifest.xml file:
<application android:icon="#drawable/icon" android:label="#string/app_name">
<activity android:name=".HelloAutoComplete" android:label="#string/app_name">
So it can't communicate with strings.xml.
I changed my layout XML file name and found out later that of the XML file (widget provider in this case) still refers to the old layout XML which doesn't exist, and that prevented the auto generation/correction of R class.

Categories

Resources