Intellij android resources gen - android

I'm experiencing a strange behaviour from Intellij that I never had before. I don't know if it's related with this new update (14.0.3) or what. So what happens is every time I add a new resource, let's say a new .xml or a new View in a previous .xml file, my R file doesn't get updated, I've to compile the hole project again, otherwise it warns me about not finding that resource. I've tried to delete the gen folder but it doesn't work either and it gets worse, all my R references get mixed up so I end up with CastExceptions and misplaced drawables, the only was is to re-compile again... It never happen to me before.
Anyone experienced this kind of behaviour?

Four Suggestions:
1) Make sure that you are indeed using the latest-greatest Android SDK Build Tools.
2) You could probably use lint to determine the lint warnings. Go to File > Settings > and search for lint in the search box. You will find lot of different options in there. Make sure they are checked. I have had some instances when lint would complain that i am using an attribute in the .xml that is not supported and that sometimes catches Intellij off guard.
3) Go into the project structure and at the very bottom there should be a tab Problems. Make sure that tab is clean. Sometimes if there is an issue with the path while using third party libraries, R.java breaks.
4) Make sure you are indeed using the correct api's available for the target/min SDK you specify.
Hope this helps. If you find the solution please update the OP so that it might be helpful to someone else.

So I've contacted JetBrains support and their response was:
Andrey Dernov (JetBrains Support)
Feb 16, 11:41
Hello,
There was a bug with Android projects https://youtrack.jetbrains.com/issue/IDEA-135234 . The issue will be fixed in upcoming 14.0.4 update. Or you can use the last EAP build from https://confluence.jetbrains.com/display/IDEADEV/IDEA+14.1+EAP . We are sorry for inconvenience.
JetBrains, Inc
http://www.jetbrains.com
"Develop with pleasure!"

Related

Adding Support Libraries to Android project

Why am I having such a hard time getting into the swing of Android development? I've been developing in various languages over the years and, for some reason, just can't seem to get beyond that "jeez-i-still-feel-a-total-noob" stage with Android.
So I'm trying to add an Action Bar to my Android 2.3.3 project. No problem, right? The Android developers website has a nice and clear article explaining exactly how to do it. Of course it involves adding the appcompat v7 support library. No problem, even this is documented step-by-step on this page. But, as with just about every such exercise in Android, I find that you can do exactly what the page tells you to do, it still won't work without significant amount of Googling to fix the errors that you encounter afterwards.
So I've followed the steps under "Using Eclipse" in the section "Adding libraries with resources" in the above link. The first error I get is Unable to resolve target 'android-16'. No problem, this one I could figure out for myself but I'm curious, is there anything in the documents I've been following that would have suggested to me that I need Android 4.1.2 (API16) installed? Did I just read right over it or should I have known by myself that, to do what I'm trying to do, I would need API16?
Never mind, at least I can fix that but then I get a new problem. As soon as I add the android-support-v7-compat library to my project and click the OK button, the console output lights up with errors, the first one being:
C:...\android-support-v7-appcompat\res\values-v14\styles_base.xml:24:
error: Error retrieving parent for item: No resource found that
matches the given name 'android:Widget.Holo.ActionBar'.
and the other 60 odd errors are similar but for different given names.
I would really appreciate if anyone could help me out here. Obviously I'd like to know how to solve this particular problem but if anyone could give me some tips on how to get past this very frustrating stage of learning this new development environment, I would be ever so thankful. What is it that I should have done differently not to run into these kinds of errors, other than following the instructions on the Android Developers website step by step?
OK, I guess I should post an answer as I've eventually managed to solve my own problem.
It turns out I have to use a build target of Android 4.2.2, regardless of the fact that I'm specifically developing for Android 2.3.3 - I mean, that's why I'm using support libraries after all. I imagine it might be possible that some other lower target (but higher than 2.3.3) would still work I just used the highest one I have installed and it solved the problem.
How I was supposed to know this from following the step-by-step instructions on the Android Developers website is a mystery to me. The reason I decided to try changing the targetSdkVersion was because of the final section in the page referenced in the question. It reads "If you are increasing the backward compatibility of your existing application to an earlier version of the Android API with the Support Library, make sure to update your application's manifest." Now I'm not increasing the backward compatibility of my existing application. I'm changing an existing application that targets 2.3.3 to be able to include an Action Bar (seems more like "forward compatibility"). I tried upgrading the targekSdkVersion though as I was out of ideas and lo and behold, it worked.
Don't know if it helps you at all, but I've been struggling with a similar issue for several hours and finally managed to resolve it. In my case, inside my own project's styles.xml file, I was referencing the AppCompat style in the wrong way in the parent attribute.
I was using:
<style name="AppBaseTheme" parent="android:Theme.AppCompat">
where I should have used:
<style name="AppBaseTheme" parent="#style/Theme.AppCompat">
My mistake was in the reference to the theme.
I found that setting the Android target to 2.3.3 for the library project android-support-v7-appcompat solves this issue. You don't need to set your project's target higher, but the library's target lower.
You have pinpointed the all important document and the relevant section "adding libraries with resources":
http://developer.android.com/tools/support-library/setup.html
The error suggests that your project is not able to find these resources. Please double check the following :
You have checked "is library" on the library project
You have exported the jars IN THE LIBRARY PROJECT as described in that section
You have added the library project as a reference to your app project
You have added the android-support-v4.jar to your libs folder in your app project
If this is all definitely correct, check eclipse for any error messages - is it the library project or the app project that lights up like the proverbial Christmas Tree ?
First of all check if you have done all the described steps as explained on the developers site. Then, for the errors :
Unable to resolve target 'android-16'
Make sure that you have installed API16, this errors occurs if you have mentioned your targetsdk to 16 in your Manifest while the sdk for API16 is not installed. You can either install the API or edit the targetApi of your project to the minimum required version, for the support library you are using I think API 11 is the minimum required android version.
android:Widget.Holo.ActionBar
This error should also be fixed once the targetsdk is fixed in your project. Since to use Holo.ActionBar you'l need to target your project to minimum supported api level ie. 11 or higher.
I met similar problems. Using API 18, ADT.
To solve the "Unable to resolve target 'android-16' problem", I remove the import lib project and repeat what the tutorial says.
Then I found I couldn't really "add" the library to my project. (The instruction "In the Library pane, click Add." there is not that detail.
1. In your project -> properties -> Java build path -> Libraries -> Add Library... -> Android Classpath Container -> Select the lib project
2. In your project -> properties -> Android -> add... -> choose the lib -> apply
cheers
Here is how I avoided the error, " Unable to resolve target 'android-16'", when adding v7.
First, I followed the instructions for adding support libraries with resources in eclipse. Following step 4, I clicked Finish. That's when I saw the error message, android-support-v7-appcompat] Unable to resolve target 'android-16'.
Second, I read this post. I also opened the download manager, but did not need anything updated. In order to make sure that I followed the steps exactly as correctly as I could, I deleted the android-support-v7-appcompat project and started over.
This second time I didn't check any different boxes, after all. But, I also got no errors at step 4. Who can say why?
Thanks, Dewald, you expressed in this question the same frustration I have. Is experience the only way out?
If some of your resource xml files cannot find their respective AppCompat references, make sure you also add the support libraries to your project properties. You do this by:
1.) right clicking on your project in the project
2.) Select properties. (Bottom of the menu)
3.) click Android on the left hand side menu of the new pop up window
4.) In the libraries section, click the "add button"
5.) Select the respective libraries. (If none show up, check to see if they are already displayed in the "libraries" window of the pop up menu. If there is a red x by the desired library, try and resolve that issue first.)
6.) Once there is a green checkmark next to the desired libraries, make sure the "Is Library" option in the libraries section IS NOT selected.
7.) Click apply.
8.) Close the pop up menu.
If this doesn't work, let me know and I can help you out. I spent three hours on the problem so I know pretty much all the possible things that can go wrong with the set up.
Go to Project -> uncheck Build Automatically
Go to Project -> Clean... , clean both the library project and your app project
Export your app as a signed APK while Build Automatically is still disabled

java.lang.NoClassDefFoundError with external jars in Android project

I've been searching the internet for two days now, and I feel like I've tried everything.
Please let me know if any code snippets might be helpful in finding a solution.
I've created an android application with the standard login activity. In the doInBackground()-method, I invoke a static method from another external class. Since this method will be invoked once the submit button is clicked, the error occurs during runtime. The class is included in my file, and there are no compilation errors. Whenever I tap/click on the Submit-button, I get a java.lang.NoClassDefFoundError referring to a class (in my external jar) that is used and properly included in my external file I refer to in the doInBackground()-method.
All my external libraries are in the 'libs'-folder. I've tried adding them to the build path manually instead and checking the boxes next to them in the 'order and export'-tab instead of the checkbox next to the 'Android Private Libraries' entry. I've tried putting the 'gen'-directory above the 'src'-directory, which didn't change anything either. Restarting eclipse, reimporting the project as a whole, playing around with the order of the external libraries in the build path, fixing project properties and cleaning the project over and over, nothing helped. I've checked this
http://javarevisited.blogspot.de/2011/06/noclassdeffounderror-exception-in.html
and tried every solution, but none of them worked for me. I ad a similar problem with a library before, and I could solve it by changing some build path settings and restarting Eclipse. However, this just doesn't work for me any more. I hope anybody has another solution or an idea, I have no clue what's wrong...
Thank you all in advance!
Yeehaw
Edit:
Despite creating a whole new project and adding my previous files to this new project, I still had the same problem in the new project. I think I figured out where this error came from: When I added my external library, I still had dependencies from the just added .jar to other jars. After adding those as well, the compiler said I needed the java.rmi.Remote class, which is in Java's JRE system library (rt.jar). Adding the whole jre library to my project made the compiler error disappear, the runtime error, however, still persisted.
After some more research I found out that my external library is probably not compatible with the android runtime environment, which means that the jar's .class-files don't have an equivalent .dex-representation which is neededfor the Dalvik virtualmachine on android powered devices. For many java jar's, especially those designed for use with the android platform, those problems don't occur.
Please correct me if I'm wrong, but this explanation seemed pretty plausible to me. Too bad, since this is the only way to currently access our database programmatically.
Make sure you've updated to the latest version of ADT Eclipse plugin and SDK Tools and also make sure "Android Dependencies" is checked in your project properties.

How do I fix Eclipse CDT Error "Function 'isdigit' could not be resolved" with Android NDK?

I am using Eclipse Indigo with an Android/NDK mixed project. I've added C++ nature and almost everything is working. Automatic builds work; that is, when I edit a file ndk-build is invoked and completes successfully - no build errors. Mouseover code assist works (the little window pops up with information about the function). If I place the cursor on an include line and press F3, a relevant header file open (not the one I would expect based on my configuration, but a relevant one - maybe a clue?).
If I select the following line in my .cpp file, it opens $NDKROOT/platform/android-3/arch-arm/usr/include/ctype.h:
#include <ctype.h>
(isdigit is defined in this file)
However, Eclipse insists that isdigit is not defined. I have read many posts suggesting that either the static analyzer or the indexer is to blame, but I've tried many of the suggested solutions to no avail.
If I add a line like the following, the error goes away and mouseover code assist for the function works:
extern int isdigit(int);
Again, this is not a linker error or a compiler error - ndk-build completes with no errors. This is something inside eclipse. Thanks for taking a look!
Edit: I now believe this to be a Code Analysis problem. A better solution is to edit the Code Analysis options to make "Function could not be resolved" be a warning instead of an error. That way you can see the warnings in Problems view, but continue to work. If the function is REALLY missing, the compiler will tell you! I also have a new theory, that the problem is with the Code Analyzer following symlinks, because all of the "missing" functions are in symlinked include files. Would love any input on this theory.
After spending several days working on problems like this, I developed the following recipe for dealing with issue.
I hope it helps you or others:
Summary: Usually, your problems in eclipse are due to eclipse configuration problems. The following assumes that your C++ code is building ok with ndk_build or ndk_build.cmd (on windows).
No joy with eclipse juno (4.2) and CDT version 8.1. Use eclipse indigo (3.7)
Make sure that you have the CDT for indigo installed and enabled (version 8.0X) by looking in the "install new software". It defaults to installed but not enabled on indigo on some downloads.
When you are dealing with native code or android config for native code, make sure you are in the C++/C perspective in eclipse, not the java one. It is deceptive, but there is a only a subset of options available in Java perspective. You can be sure you are C++/C perspective if you see "C/C++ general" as a choice when you do "Project > Properties."
The usual problem is that the indexer in C/C++-land thinks there are errors when there is not (e.g. building with ndk-build works ok, often you can see this in the console window even). This is caused by bad paths in the "Paths And Symbols" part of "Project > Properties > C/C++ General" on the first tab.
To fix the problem, the primary tool is to right-click on the project, select "Index" and "Search for unresolved includes." This will tell what files it can't find--and these are typically not the ones that you have in your files with the little pink mark by them.
To find the right file, search in your NDKROOT directory (where you installed NDK). A typical one to add is: ${NDKROOT}/platforms/android-9/arch-arm/usr/include or the right android-N for your android target. There are many copies of the standard include directories in the NDK because of multiple versions of android and copies of the C++ standard libraries.
Two big warnings
The "unresolved includes" view in eclipse does not automatically update when you change the indexer configuration on the Properties > C/C++ General/Paths and Settings so be sure to run it again each time. Most views in eclipse do this update properly!
Also the little red/pink error markers in the source code views in the eclipse editor don't automatically update either. You have to "touch" the file in some way for it discover that the error is now fixed.
I worked around this issue via the approach I suggested in my question and haven't been able to find a better way yet.
Perhaps this will help:
Go to Project > Properties
Navigate to C/C++ Build > Settings
Go to GCC C Linker > Miscellaneous settings
Add the following in the Linker flags : -lc
Have you tried rebuilding the indexer? (right click project in project explorer index->rebuild)
Sometimes that takes care of problem... If you upgraded from an earlier version of eclipse your indexer setup could be a problem -- you might want to try restoring the indexer defaults (preferences c/c++ Indexer)... Hope this helps – this issue can be 'maddening' (seems to happen way to often)
I had the same problem on Linux with different toolchains. Even the simplest C++ code (like the one create by the hello wizards) would have syntax errors, without aby build problem. As pointed out in another post by Thorbjorn Jemander the problem is in the indexer and it can be eliminated by deselecting the option "Allow heuristic resulution of includes". Explicitely: Winsow -> Preferences -> C/C++ -> Indexer -> deselect the above option.
After that you may see that highlighted errors disappear after you open the file in editor and just click within the editor page...

Android unable to resolve classes from external jars

I came across this after updating my SDK tools from revision 15 to 17, seems like there are quite some changes under the hood that cost me a long evening. Figured I share this so I hopefully save somebody else's nerves:
After updating my project would still compile and build, but at runtime throw all kinds of errors and exceptions NoClassDefFoundError, ClassDefNotFoundException or the dalvik vm complaining in logcat that it was not able to resolve some classes or super classes. Turned out that it was not able to load classes that were located in external jar files (which were on the classpath).
SOLUTION / ANSWER: (unfortunately stackoverflow does not let me answer this due to lacking reputation)
Turns out that since revision 17 of the sdk tools, only external libraries that are marked to be exported in java will be part of the apk at runtime. So the solution is simple:
Go to Java Build Path -> Order and Export and check the box next to all your jars that you need at runtime (should usually be all of them).
I'm not sure whether I should have done that before, but with revision 15 and earlier this was never an issue.
Just add the library Jar files to you apk. Its very easy to do it.
Right Click on the project and click on properties.
Click on the Java Build Path and move to the Order and Export Tab.
Click on Select All on the right side. Click on ok.
Re-build the application and try running the application.
Now it should work. Lemme know if it worked for you.. ?

What can I do with R cannot be resolved problem?

If I make a new Android project in Ecplipse and I try, to open one of the samples from android SDK, I have got an error, look like this:
R cannot be resolved
What can I do, to be able, to run these files? I tried to delete import android.R; but nothing changed.
Thanks
First thing you might try is "clean" your project (option in the menu). If it persists:
There should be an error that stops R from being generated. Check the "problems" tab (?) in eclipse to see what that problem is, and solve that. It could be missing libs, or various other stuff.
You possibly got error in building resources.
Possible fixes:
-refresh your project (F5)
-clean you project and refresh
-see "Console" tab, sometimes the problem is shown there
-reload the Android SDK
-restart the Eclipse IDE
Check your XML-Layout files. The problem come here half a time.
If you are sure it is note your layout file, check in your java build path if the google librarys are well set. (Google APIs)
(sorry for my bad english)

Categories

Resources