I have an Android project with native code. I'm able to build native code from command line by calling ndk-build command with no errors or warnings. But when I open it in ADT it shows the following error.
Error message: Method CallStaticIntMethod could not be resolved. There are many files with similar errors in the project.
I double checked configuration and here is what I have. Android build, tool chain and includes are properly configured (see pictures below)
Required includes are also visible in the Project Explorer and they are valid (not empty and point to correct header files).
But when I Clean the project and Build it, the errors are still there. Any ideas on how to solve this?
Configuration: ADT 22.6.2, NDK r9d (64-bit), OSX 10.9.2
After some struggling with preferences, I finally found a solution. This is a bug in NDK plugin which was reported to AOSP but not yet fixed. A past of the answer is described in comment #50. Here is the sequence which worked our for me.
Open Project Properties -> C/C++ Build -> Tool Chan Editor
In the section Used Tools replace Android GCC Compiler with GCC C Compiler. If section is empty, just add GCC C Compiler entry in there.
Open Project Properties -> C/C++ General -> Paths and Symbols and add directories, where your h-files to be included are located. Use Move up button to add a folder with your local includes (/AudioPlayer/jni in my case) to the first place. Then add platform and toolchains includes. Built-in includes should stay at the very bottom.
In my case the full paths to the toolchain includes were like below. These are built-in paths of original Android GCC Compiler toolchain, which we have replaced at step 2.
/Tools/android-ndk/toolchains/arm-linux-androideabi-4.6/prebuilt/darwin-x86_64/lib/gcc/arm-linux-androideabi/4.6/include
/Tools/android-ndk/toolchains/arm-linux-androideabi-4.6/prebuilt/darwin-x86_64/lib/gcc/arm-linux-androideabi/4.6/include-fixed
Press OK button, clean and re-build the project. All errors must go away. If they stay, try to remove them from Problems view and re-build project once again.
Update: I have found another place, where you can add paths to include files. However it appears to be Eclipse version dependent. Project Settings -> C/C++ General -> Processor Include Paths, Macros etc. -> CDT User Settings Entries -> Add. After I added the paths listed above, there is no compilation issues anymore. Development is fun again.
Yes, its caused by the IDE not knowing where all of your headers and any libs you linking again are. The errors are generated by the IDE's autocomplete/bug system. You can either fix your includes within eclipse or remove them as errors in the preferences.
I had a similar error and solved it by going to project->properties->discovery options and changing the discovery profile from managed build system to GCC, after changing to GCC C Complier from Android GCC Compiler and updating the include directories.
Related
I recently upgraded my NDK from android-ndk-r9 to android-ndk-r10 (r10d to be exact). Eclipse is 4.4 Luna (Luna Service Release 1 (4.4.1); Build id: 20140925-1800). Eclipse is fully patched for its release. I updated all the Eclipse plugins (including ADT) so they are fully patched. And I also changed my ANDROID_NDK_ROOT in .bash_profile to point to the new NDK directory.
Under the Eclipse Preferences → Android → NDK, Eclipse is showing the new android-ndk-r10 path (I had to set it manually).
Under the Project Properties → C/C++ General → Paths and Symbols, Eclipse is still showing the old android-ndk-r9 path.
Eclipse considers the path built-in, and unchecking the Show built-in values check box makes all the paths disappear. In addition, the Edit... button is greyed out.
I've grepped the following directories, and I cannot find the string "android-ndk-r9":
My Eclipse workspace
~/.eclipse
The project's directory
~/Library
/Application/Eclipse
/etc on the OS X machine
/Library on the OS X machine
The project builds fine. The bad configuration just creates hundreds of errors in the list on the Problems tab. (To duplicate, you need to open a C or C++ file):
Where is the setting coming from? And how do I change it?
This appears to be related: How to remove auto-discovered paths after compiling on Linux from Eclipse CDT project?. But I can't find Discovery Options → Clear discovery entries now (it appears to be a Eclipse 3.x feature). Ditto for Eclipse CDT Invalid Project Path.
This appears to be the Eclipse bug report covering the issue: Include path discovery doesn't discard obsolete paths on compiler upgrade.
Where is the setting coming from?
It appears the information is held in the project's pathInfo file. Below, the project is a sample JNI project called AndroidPrng.
$ cat /Users/jww/Eclipse/.metadata/.plugins/com.android.ide.eclipse.ndk/AndroidPrng.pathInfo
t,1421045575000
i,/opt/android-ndk-r9/sources/cxx-stl/stlport/stlport
i,/usr/local/cryptopp/android-armeabi/include
i,/opt/android-ndk-r9/sources/cxx-stl/system/include
i,/usr/local/cryptopp/android-armeabi/include/cryptopp
i,jni
i,/opt/android-ndk-r9/platforms/android-14/arch-arm/usr/include
i,/usr/local/cryptopp/android-x86/include
i,/usr/local/cryptopp/android-x86/include/cryptopp
i,/opt/android-ndk-r9/platforms/android-14/arch-x86/usr/include
i,/usr/local/cryptopp/android-mips/include
i,/usr/local/cryptopp/android-mips/include/cryptopp
i,/usr/local/cryptopp/android-armeabi-v7a/include
i,/usr/local/cryptopp/android-armeabi-v7a/include/cryptopp
i,/opt/android-ndk-r9/toolchains/arm-linux-androideabi-4.6/prebuilt/darwin-x86_64/lib/gcc/arm-linux-androideabi/4.6/include
i,/opt/android-ndk-r9/toolchains/arm-linux-androideabi-4.6/prebuilt/darwin-x86_64/lib/gcc/arm-linux-androideabi/4.6/include-fixed
i,/opt/android-ndk-r9/platforms/android-14/arch-mips/usr/include
d,__STDC__,1
d,__INT64_MAX__,9223372036854775807LL
d,__LDBL_HAS_QUIET_NAN__,1
d,__WINT_TYPE__,unsigned int
d,__ORDER_LITTLE_ENDIAN__,1234
d,__DEC64_MAX_EXP__,385
d,__UINT_LEAST32_TYPE__,unsigned int
d,__UINT_FAST64_TYPE__,long long unsigned int
d,__GXX_WEAK__,1
...
I've grepped the following directories ... "My Eclipse workspace, ~/.eclipse, " ...
There were two problems here. First, the project is located on my desktop, and not my workspace directory. Second, the 100's of entries in the log files under org.eclipse.cdt.ui drowned out the entries 15 entries for com.android.ide.eclipse.ndk.
So, before you grep, perform:
rm Users/jww/Eclipse/.metadata/.plugins/org.eclipse.cdt.ui/*.log
That will produce manageable grep results.
And how do I change it?
Exercise left to the reader.
You can edit by hand; or you can delete it and Eclipse will recreate it with the new NDK-related paths.
OP probably figured this out already but adding this here just for future reference.
Eclipse (currently) has issues with the r10d version (see the related discussion in https://stackoverflow.com/a/28108753/1591421). First, if possible one should rollback to an earlier version of the Android NDK (e.g. r10c seems to work just fine) and then make Eclipse point to the newly installed version of the NDK: Preferences -> Android -> NDK -> NDK Location. To let Eclipse pick up these changes the project needs to be deleted from the workspace and then added back (at least I had to). After the project has been re-imported one should see the NDK paths updated: Project -> Properties -> C/C++ General -> Paths and Symbols. Rebuilding the C/C++ Index (Project -> C/C++ Index -> Rebuild) won't hurt either :)
On my Windows platform, I have the latest version of adt bundle (20140321) and ndk (r9d) installed. The installation is as clean as it gets. The environment variables NDK_ROOT, PATH, etc. are all defined properly.
The app I am working on has some C++ native code. The code builds fine both outside Eclipse as well as within Eclipse.
The problem, however, is that the editor complains that jni.h is an unresolved inclusion.
Project-->Properties-->C/C++ General-->PathsAndSymbols shows include directories and one of the directories is C:\adt\ndk\platforms\android-19\arch-arm\usr\include. I have verified that jni.h is present in this directory.
I have already checked all other messages on this forum but couldn't find any concrete steps. Appreciate your guidance. Regards.
I ran into a similar problem with a working project with Android NDK-based code after updating to Eclipse Kepler. I observed similar things: the header files would correctly be listed under "includes" in the project, the actual build (via ndk-build) worked fine, but Eclipse's editor couldn't locate any headers in standard system directories (all headers with < > brackets).
I tried many different fixes, including switching toolsets, rebuilding indices etc. without success.
Finally, I removed the C nature entirely from the project, and added it back via the "Android Tools" menu in Eclipse.
Removing the C nature:
The only way I could find to reliably removed the C nature from the project was by hand editing Eclipse's .project file for the project.
Close the Eclipse project (e.g. by quitting Eclipse).
Open the .project file in a text or xml editor. There will be at least 2 <buildCommand> nodes that need to be removed. Remove the <buildCommand> node with name org.eclipse.cdt.managedbuilder.core.genmakebuilder and all its children, and the <buildCommand> node with name org.eclipse.cdt.managedbuilder.core.ScannerConfigBuilder and its children. Finally, remove the lines:
<nature>org.eclipse.cdt.core.cnature</nature>
<nature>org.eclipse.cdt.core.ccnature</nature>
<nature>org.eclipse.cdt.managedbuilder.core.managedBuildNature</nature>
<nature>org.eclipse.cdt.managedbuilder.core.ScannerConfigNature</nature>
Completely remove the .cproject file.
Adding back the Android Native nature
Reopen the project in Eclipse. Then right-click on the project in the Project Explorer, and from the "Android Tools" contextual menu, choose "Add Native Support...".
Looking at the changes made in the .project and .cproject files before and after this change, it appears that it primarily gave new version numbers to the Android NDK tools. In any case, it solved the issue for me.
after add native support,right click project, add includes in c/c++ general--> paths and symbols >> includes, for example add include as %NDK_HOME%\platforms\android-19\arch-arm\usr\include
I had the same problem some days ago. I found a fix in another question here in stackoverflow, but now I can't find the link.
In Eclipse: right-click on your project > Properties > C/C++ General > Code Analysis > Launching and disable both options ("Run with build" and "Run as you type").
There seems to be a problem with CDT and the Indexer, doing this you hide the problem. The editor will still complain but now you should be able to run and debug your application.
I solved this for adt-bundle-windows-x86_64-20140321:
No any environment variables is set, just pointed NDK location under Preferences > Android > NDK.
I created new, clean Eclipse workspace.
Deleted from my project with C++ code next files/folders:
.settings .classpath .cproject .project project.properties
Eclipse > New > Other > Android > Android Project from Existing Code > then point folder with your project, let Eclipse detect it, check "Copy project into workspace" and click Ok/Next, whatever.
Clean project.
Right click on project > Android Tools > Add native support
Rebuild, possibly restart workspace.
Also this solved issue with Eclipse 4.3 previously ignored build system and user defined compiler flags. Now macros folding dependent on this flags etc works fine.
If more general - NDK plugin can properly define for you right includes and anything other required to work fine, but you need to clean your project from broken crap.
I imported an existing Android project to my Eclipse.
I get an error in the project that prevents me from building:
I get this message in "problems":
Program "/opt/adt-bundle-linux/android-ndk-r8e/ndk-build" is not found in PATH
and the problem type is: C/C++ Problem.
I have a windows machine with Eclipse (ADT) and Java up to date and I suspect that the original project where this project was built, is different (perhaps it is Linux?), or perhaps it makes use of native code and my Eclispe is not configued to support it. I don't have such an issue with other projects in my Eclipse...
Please, advise....
thanks.
as Chris Stratton stated, this project is made on a Linux machine.
You can change your PATH if you go to: Project -> Properties -> C/C++ build -> Environment
You can edit PATH there. After you've deleted that "/opt/.." you should add the path of your own ndk-build. If you don't know what ndk-build is take a look over here: https://developer.android.com/tools/sdk/ndk/index.html
I'm looking to incorporate the NDK for C++ code use in my Android project. I'm using Eclipse Android IDE and I've just downloaded android-ndk-r9-darwin-x86_64.tar.bz2 for OSX 64bit. I've uncompressed the ndk and have it in my home folder, but when I attempt to setup the path inside Eclipse prefs, I get this error
I've looked at this similar question (Eclipse error: invalid path for ndk?) for answers, but every suggestion didn't solve the problem. Other relevant information, I have Make 3.8.1, up-to-date SDK, Sequoyah.
I had the same problem and documented the solution to this problem. It are the first 2 steps of the next link you'll need:
http://aplacetogeek.wordpress.com/android-with-opencl-tutorial/
Edit:
The solution is this:
Step 1: setup Android NDK
Download the NDK from:
http://developer.android.com/tools/sdk/ndk/index.html
I unzipped it in the adt-bundle but you can unzip it anywhere you
want.
Note or remember the path you used. I'll need it in the next steps!
Go to Window -> Preferences -> Android -> NDK
Browse to android-ndk-r9c.
Example: /home/dries/AndroidDev/adt-bundle-linux-x86_64-20131030/android-ndk-r9c
Click apply and ok
Step 2: configure Android NDK for your project
Right click on your project folder. Choose android tools -> add
native support (! the bottom one !) and click finish.
The file you just created is going to be your own .so file. This
will be your personal library with the functions you create yourself
in the JNI folder.
Now you should see a JNI folder in your project with a .cpp and an
Android.mk file in it.
Go to project -> properties -> C/C++ build -> build variables -> add
Name: NDKROOT
Value: your android-ndk-r9c folder you also added to NDK in step 1.
Click Ok
Go to C/C++ build and uncheck Use default build path.
Change the
build path to ${NDKROOT}/ndk-build. Make sure you did not end the NDKROOT value on / !
Click apply
You should be able to use the NDK now and compile without errors.
Found a work-around solution to my question with the help from this forum: https://groups.google.com/forum/#!topic/android-ndk/YPFPa9Fen7Y
I downloaded an old copy of the NDK (r5b) and there were no errors when setting up the path, as opposed to r9 the most recent version. As the forum says, the problem lies with Sequoyah which has not updated since 2011 and can not recognize the new structure of that the NDK is laid out in. Hope this helps someone in the future. (If you find a direct solution though, let me know.)
Instead of downloading another version of the NDK, I simply created links inside the build folder to the toolchains, prebuilt and platforms which recreates the folder hierarchy of the r4 NDK.
Doing this made the plugin happy, and I only have one version of the NDK on my computer.
After updating to the latest developer tools, ADT 14, my Android project that includes library projects will no longer run producing the error:
Dx UNEXPECTED TOP-LEVEL EXCEPTION: ... already added: ...
...
Conversion to Dalvik format failed with error 1
The other threads describing this issue with solutions that include removing and re-adding the projects do not work.
This problem is listed as a known issue of ADT 14. Here's the quote from the Android Tools Project Site:
Project not building with error
[2011-10-20 23:32:04 - MyApp] Dx UNEXPECTED TOP-LEVEL EXCEPTION:<class>: already added: <class>
This is due to a failure to remove previous library source folders from the
main project. Incidentally, the fragility around those linked source
folders is one of the reason we are moving away from this mechanism
(see more info at
http://tools.android.com/recent/buildchangesinrevision14). The
solution is to remove those <libraryname>_src source folders from
your projects. Just right click them and choose Build Path > Remove
from Build Path. You should also be prompted to remove the linked
folder which you should do. If you're not prompted, remove it
manually. You can see some screenshot of the problem in this great
post:
http://android.foxykeep.com/dev/fix-the-conversion-to-dalvik-format-failed-with-error-1-with-adt-14
Solution:
As it says, the solution is to remove the <libraryname>_src source folders from your projects. You can do this by right clicking them and choose "Build Path -> Remove from Build Path" or in your project properties (Java Build Path -> Source tab).
I also ran into this problem, but none of the above fixed it:
Tried removing/re-adding libraries with clean builds along the way
Tried deleting and re-importing projects
No dice. Still the "Conversion to Dalvik format failed with error 1" was staring me in the face every time I tried to export to an apk.
I could tell the problem was related to ProGuard, because when I commented out this line in my project.properties file, everything worked fine:
proguard.config=proguard.cfg
However, I wasn't able to solve the problem until I found this post by David M Young. Apparently, ADK/ADT 14 shipped with an incorrect version of ProGuard (oops!). I downloaded ProGuard version 4.6. Replaced the android-sdk\android-sdk\tools\proguard\lib directory contents with proguard4.6.zip\proguard4.6\lib (3 *.jar files), restarted Eclipse and export to apk worked again!
To solve you should:
Right click on your project>Properties>Java Build Path and remove all libs but the one Android I.J (depending on your version)
Project>Clean
Add back the libs you've removed
If the problem comes back another times it's useful to put the libs outside your project and import them as "External JARs"
Hello thought I'd throw my two cents in here. as I did do that,
"_src -> Remove from path"
Then I cleaned it and rebuilt and I could get it to run in debug mode on my phone just fine. I could also export it; but only if I disabled proguard. of course I couldn't leave it like that with my code open for all to see. so it was quite madding. but I Finally found a cure, oddly enough they had the same problem (and fix) with r12 as they do with this one.
it's in: [Android SDK Installation Directory]\tools\proguard\bin\proguard.bat
Change
call %java_exe% -jar "%PROGUARD_HOME%"\lib\proguard.jar %*
to
call %java_exe% -jar "%PROGUARD_HOME%"\lib\proguard.jar %1 %2 %3 %4 %5 %6 %7 %8 %9
I tried tons of other stuff but this is what did it for me.
This is a known problem with the android sdk. Check out this blogpost for a fix.
I used a library for my project and had the same error - it was solved by removing library and src-folder, cleaning and adding it back and cleaned again.
Remove
Project properties -> Android: Remove libs, 'Apply'
Remove included library src-folder
better clean,
Add again
Project properties -> Android: Add libs again, 'Apply'
Clean project
Just had this problem come back again (fixed first time by removing the _src items as mentioned in other answers) - this time there were no _src files to remove. The error was relating the android-support-v4.jar which was included as part of a linked library project as well as part of the main project itself.
Error Dx UNEXPECTED TOP-LEVEL EXCEPTION:
java.lang.IllegalArgumentException: already added: Landroid/support/v4/content/ModernAsyncTask$WorkerRunnable;
Problem went away after removing the android-support-v4.jar file from the build path for the main project. Don't think I came across this as possible cause to the errors.
Go to Project » Properties » Java Build Path » Libraries and remove all except the "Android X.Y" (in my case Android 1.5). click OK. Go to Project » Clean » Clean projects selected below » select your project and click OK. That should work.
It is also possible that you have a JAR file located somewhere in your project folders (I had copied the Admob JAR file into my src folder) and THEN added it as a Java Path Library. It does not show up under the Package Explorer, so you don't notice it, but it does get counted twice, causing the dreaded Dalvik error 1.
Another possible reason could be package name conflicts. Suppose you have a package com.abc.xyz and a class named A.java inside this package, and another library project (which is added to the dependency of this project) which contains the same com.abc.xyz.A.java, then you will be getting the exact same error. This means, you have multiple references to the same file A.java and can't properly build it.
I had the same issue, I'm using the ADT 20.0.3.
Steps I followed to resolve this.
Remove all the jar in project/lib folder and reference them as external jars.
Check android dependencies/reference libraries in project for duplicates,
I've dealt with this problem when using Sherlock ActionBar library in my project. You could do the following step, it's work for me.
Right click to your project, select properties.
A dialog will show up, select 'Java build path' on the left menu.
Remove 'Android dependencies' and 'Android private libraries' on the right panel then click OK
Clean your project (select menu Project --> Clean)
Right click your project, select Android Tools -> Fix project properties
Clean project once again.
Restart your computer
Open eclipse and Export apk
Hope that will help you.