Duplicate classes R & BuildConfig after "Reimport All Maven Projects" - android

We are building our Android projects with Maven and IntelliJ IDEA. Sometimes we must execute "Reimport All Maven Projects", e.g. to update dependencies. The problem with that is that it always messes up the source folders for resources: all modules get "gen" and "target/generated-source/r" which seems to be the cause for the duplicates. So after reimporting, we need to manually delete one of those (usually the "gen" folder). Of course, we want to avoid this step. We tried several settings for the Android facet, but no luck so far.
So, how can we configure IntelliJ to do a proper Maven reimport that just works?

According to the reply of Sven Strohschein at http://youtrack.jetbrains.com/issue/IDEA-94901 you can try to:
Delete the "gen", "target" and "out" folders
Revert the changes within the "ipr" and "iml" files (or just delete them all, maybe even .idea folder)
Start IntelliJ 12
Open the pom file
Right click -> "Maven" -> "Reimport"
"Build" -> "Rebuild project"
Works fo me.

After IDEA detects and adds Android facet to module, it would start generating gen folder at usual place, but maven-android-plugin generates its own under target directory.
You need to tell IDEA to place generated files at same place where maven-android-plugin creates them.
First, use module's android facet settings and check the option to use Maven goal instead of generating by itself:
Then, go to module's settings and set output path same as Maven's, which is target directory:
Delete gen directories, Do mvn clean to clear all unnecessary files.

From your description above I guess that your project structure differs from the maven default. See Introduction to the POM. But I think the android android:generate-sources is more interesting if you have changed the assets directory etc.
Example:
<sourceDirectory>${basedir}/src</sourceDirectory>
<outputDirectory>${basedir}/target/classes</outputDirectory>

Related

Android studio project files missing from source control

I am looking a source code repository and it only contains code for an Android project i.e. src/main/java/com/.. and no project definition files such as .idea, .iml ,.ipr, .iws - These files are included in the .gitignore file.
There are no files relating to an Android Studio project at all so I cannot open in the IDE. It has been set up for Maven so I can build that way. If I want to run/debug/alter this project what do I do?
Why would somebody exclude all IDE project files?
It's easy, the repository/source code owner don't commit the project files because the source code must be independent of the IDE used by people. The projects files of Eclipse are different from one of IntelliJ.
You can clone or download the source code and even not use any IDE. Some poeple prefer working with editors like Emacs or Vi and build the project using the command line.
There are many ways to create android projects with Android Studio and Eclipse being the main two.
If the author had to maintain project files it would add considerably to the work required as IDEs etc get updates at different rates.
This way the code is "portable" between IDEs and the author can focus on just supporting his work rather than all of the combinations of IDE/Operating Systems.
My Solution
I am posting solution here as I cannot yet answer my own question.
So, I the solution was in the Maven definition. My codebase was an SDK consisting of numerous libraries and sample apps. Each component had a POM.xml and was all contained using a Parent POM.
All I did was import the Parent POM into Android Studio. Once triggered Android Studio would create its own project files using the POM definitions for each component. All the modules were available in one instance and it built and ran instantly. It was truly beautiful :)
Steps: Import Project -> Select directory containing POM.xml -> "Import project from external model" -> Maven -> Next -> continue to create project.

Android dependencies error after renaming project

I renamed my Project:
after that i got the red callsign at my Project(which you see in the first Image) and this:
also my projectproperties says this but i'm not sure if this was also the case before renaming:
even that the path is(!) spelled correctly.
I referenced the libaries to my Project:
But i'm not able to fix the Problem. Still he doesn't recognize the Facebook and GPS libs in my Project..
I also checked this:
Libraries do not get added to APK anymore after upgrade to ADT 22
this:
accidentally removed android dependencies folder
and this...
Completely renaming a project in Eclipse
but nothing did the trick.
Any help is appreciated.
(following up after some comments)
If your project is broken after a refactor and you are going crazy to figure out what's wrong you can consider to create a fresh new project.
Create an empty project starting from the existing one is really simple, just follow this steps:
Create a new project with the desidered name
Copy oldProject/src/ to newProject/src/
Copy oldProject/res/ to newProject/res/
Copy oldProject/libs/ to newProject/libs/
Copy oldProject/AndroidManifest.xml to newProject/AndroidManifest.xml
Check that your project's classpath is set correctly, same for other dependecies.
Refresh all the projects in the workspace (one by one)
Clean (yes, it's always a good idea)
Build all
For each of your projects, verify dependencies in project references & java build path:
File -> Properties
"Java Build Path"
verify, that all projects, referenced by current project, are added.
"Project references"
verify, that all projects, referenced by current project, are checked.

java.lang.ClassNotFoundException android + eclipse + maven + osx

I'm trying to implement maven into an existing android project.
I've done so through the context menu > Configure > Convert to Maven project. And everything seems okay, no warnings or errors.
But when I try to run the app (just like before) I get:
12-31 10:16:57.423: E/AndroidRuntime(14242): java.lang.RuntimeException:
Unable to instantiate activity ComponentInfo{xxx/xxx.MainActivity}:
java.lang.ClassNotFoundException: xxx.MainActivity
I've followd all the instructions on implementing m2e and everything looks like it should work.If I don't convert the project to a maven project, the app runs fine.
Any suggestions where I'm failing?
This is what my pom.xml looks like: http://pastebin.com/ByXA0BP4
This took me ages to resolve and it was the OP's answer which guided me.
After enabling Maven for the project, you need to disable "Allow output folders for source folders"
Steps:
Project Properties -> Java Build Path -> Source Tab -> Untick "Allow output folders for source folders" -> Click OK
I also noticed that I got the following message in the console, which led me down a rabbit warren of false leads:
trouble writing output: already prepared
I figured it out myself.
After converting the project to a maven project, right click on the 'src' folder and chose Build path > Use as Source Folder
Now the project runs fine
ClassNotFoundException is simple, the respective jar is not there in class path.I checked your pom.xml, but i was unable to relate any dependency that could have xxx.MainActivity.
So just ensure that respective jar is there as dependency artifact that contains MainActivity. If it still would not work, try copy pasting the jar manually into deployment\lib folder and it should work. Another option could be to debug your current CLASSPATH location and see if your jars are there or not.
Also by default Maven probably would not update dependencies. You have to right click->Maven-> Update Project to download any newly added dependencies in your pom.xml. There might be an error downloading dependency for that you have you to find the right repository or download the jar locally and install it as local artifact.
Thanks
You may check if the virtual or real device where you are testing the app is actually compatible with the target Api of the project. Change it to the proper one and check again.

How to remove a dependency from my Android project in Eclipse

When I highlight my project, go to properties, select java build path and then try to remove an Android Dependency from my list of Android dependencies the remove button is grey'd out. How can I remove that specific dependency?
JFTR:
I have had similar problem after a messed merge of two projects branches on Eclipse. I could revert the merge as I did not commited yet, but Eclipse project files that I do not store in my repository was messed.
The solution for me was to:
Delete the error message from "Problems" view.
Clean the project (Project / Clean...)
Solved!
Delete the dependency from the libs folder.
Well, the above solutions didn't work for me so I just enter the project.properties file and remove the dependency (which is written there as a reference).
These are the steps on Ubuntu:
Using console on project root folder type sudo vi project.properties
Go to the line that you want to remove and delete it (you can type double d to remove a line --> dd)
Close and save the file (press ESC and then wq)
Clean the project and rebuild.
Note: Before you change project.properties manually you are strongly advised to backup your project since this operation is unsafe!!!
Sorry for the elaboration for those who speak fluent Linux.
2 types of dependencies I can found so far under Android Dependencies:
Build path to your workspace libs folder
Build path to some other project which install by Android tools and
create as another project under Eclipse, e.g. GridLayout for
android(android-support-v7-gridlayout.jar)
To remove the first one, it is easy. Just delete the jars under libs folder.
To remove the second one, it is also easy. Just go to the project's Build Path, select Android, remove the reference item under Library panel

Eclipse: How to ignore .git subdir when adding one project to another project's build path?

I'm developing an application that is supposed to run on both Android as well as regular Java SE.
I have an eclipse project called foobar-core which contains code that is used both by the Android and the SE version. I have another project called foobar-android, which contains all android-specific code.
I need to reference some of the foobar-core code in the foobar-android project, so I added foobar-core to foobar-android in Settings -> Java Build path -> Projects -> Required projects on the build path. This works fine, as I can use code from foobare-core in foobar-android now.
Here's the problem: Both foobar-core and foobar-android are independent git repositories, which means they both have a .git subdirectory. Now I get a lot of warnings on the "Console" tab whenever I compile foobar-android. They look like this:
/foobar-core/src/.git/HEAD conflicts with another file already put at .git/HEAD
/foobar-core/src/.git/config conflicts with another file already put at .git/config
/foobar-core/src/.git/description conflicts with another file already put at > .git/description
/foobar-core/src/.git/hooks/applypatch-msg.sample conflicts with another file already > put at .git/hooks/applypatch-msg.sample
How can I tell Eclipse to ignore the .git files when importing sources from the foobar-core project?
Even if you just have a single git repo, it is good to ignore the .git directory because other Eclipse will waste a lot of time looking at the files in it even though it never needs to do anything with them. In particular, when you do a project wide search, Eclipse will search through the all the files in .git directory, which takes a long time and ends up showing you lots of duplicates (or almost duplicates, older versions of the same file with the same search term found).
I think the Eclipse git extensions probably take care of this but if you don't want to install yet another extension, the best way I have found it to tell Eclipse that all .git directories are "Derived", which seems to make Eclipse somewhat ignore the contained files.
You do this by switching from the Package Explorer view to the Navigator view, where you should see the .git folder. Right-click on the .git folder, selecting properties, selecting Resource from the settings selector, and then checking the "Derived" box.
I would setup a .gitignore file that simply ignored the entire foobar-code project.

Categories

Resources