I have one Android app which uses ActionBarSherlock & ViewPagerTabs. I use Eclipse to write and build it, and it just works well until I try to build it with Ant. Here's what I did:
go to ActionBarSherlock folder, run "android update lib-project --path ."
go to ViewPagerTabs folder, run "android update lib-project --path ." too
go to app folder, run "android update project --path ."
run "and debug" under app folder, and I got following errors:
:
[javac] C:\Android\TestApp\src\com\test\App\TestActivity.java:46: cannot find symbol
[javac] symbol : method getSupportActionBar()
[javac] location: class com.test.App.TestActivity
[javac] final ActionBar ab = getSupportActionBar();
[javac] ^
So question NO. 1: I have correct library references in app's project.properties, and ActionBarSherlock & ViewPagerTabs could be built successfully, why do I still get these errors?
There's a workaround for this issue -- copy all classes.jar under library's bin folder into app's libs folder, and run "ant debug" again. But I need to delete these .jar files under app's libs folder after all .java files of app could be compiled.
Running "ant debug" again after this, I will get following errors:
[dx] processing archive C:\Android\ActionBarSherlock\library\bin\classes.jar...
[dx] ignored resource META-INF/MANIFEST.MF
[dx] processing android/support/v4/accessibilityservice/AccessibilityServiceInfoCompat$AccessibilityServiceInfoStubImpl.class...
[dx] processing android/support/v4/accessibilityservice/AccessibilityServiceInfoCompat$AccessibilityServiceInfoVersionImpl.class...
[dx] processing android/support/v4/accessibilityservice/AccessibilityServiceInfoCompat.class...
[dx] processing android/support/v4/accessibilityservice/AccessibilityServiceInfoCompatIcs.class...
[dx] processing android/support/v4/app/ActionBar$LayoutParams.class...
[dx] processing android/support/v4/app/ActionBar$OnMenuVisibilityListener.class...
[dx] processing android/support/v4/app/ActionBar$OnNavigationListener.class...
[dx] processing android/support/v4/app/ActionBar$Tab.class...
[dx] processing android/support/v4/app/ActionBar$TabListener.class...
[dx] processing android/support/v4/app/ActionBar.class...
[dx] processing android/support/v4/app/ActivityCompatHoneycomb.class...
[dx]
[dx] UNEXPECTED TOP-LEVEL EXCEPTION:
[dx] java.lang.IllegalArgumentException: already added: Landroid/support/v4/app/ActivityCompatHoneycomb;
[dx] at com.android.dx.dex.file.ClassDefsSection.add(ClassDefsSection.java:123)
[dx] at com.android.dx.dex.file.DexFile.add(DexFile.java:163)
[dx] at com.android.dx.command.dexer.Main.processClass(Main.java:486)
[dx] at com.android.dx.command.dexer.Main.processFileBytes(Main.java:455)
[dx] at com.android.dx.command.dexer.Main.access$400(Main.java:67)
[dx] at com.android.dx.command.dexer.Main$1.processFileBytes(Main.java:394)
[dx] at com.android.dx.cf.direct.ClassPathOpener.processArchive(ClassPathOpener.java:245)
[dx] at com.android.dx.cf.direct.ClassPathOpener.processOne(ClassPathOpener.java:131)
[dx] at com.android.dx.cf.direct.ClassPathOpener.process(ClassPathOpener.java:109)
[dx] at com.android.dx.command.dexer.Main.processOne(Main.java:418)
[dx] at com.android.dx.command.dexer.Main.processAllFiles(Main.java:329)
[dx] at com.android.dx.command.dexer.Main.run(Main.java:206)
[dx] at com.android.dx.command.dexer.Main.main(Main.java:174)
[dx] at com.android.dx.command.Main.main(Main.java:95)
[dx] 1 error; aborting
My question NO.2 is: how can I fix this issue?
Thanks!
I finally resolve it myself. I find that there's a android-support-v4.jar in ViewPagerTabs' libs folder. The solution is -- deleting this android-support-v4.jar, then make ViewPagerTabs depend on ActionBarSherlock (because ActionBarSherlock actually have one copy of Support Package).
I hope it's useful for people who wants to use ActionBarSherlock & ViewPagerTabs in one application and use Ant to built his/her application. Good luck.
You stated its because both library have android-support-v4.jar. See #porter-liu answer for non-maven builds.
For people using maven, set your ViewPager dependancy as:
<dependency>
<groupId>com.viewpagerindicator</groupId>
<artifactId>library</artifactId>
<version>2.4.1</version>
<type>apklib</type>
<exclusions>
<exclusion>
<groupId>com.google.android</groupId>
<artifactId>support-v4</artifactId>
</exclusion>
</exclusions>
</dependency>
The exclusion tag stops the double import fixing the issue.
When you update lib-project, you're updating the project so that it compiles as a library. There's a separate step to update your main project so that it sees the library it requires.
For each library project you're going to use, run
android update project --library ../pathToTheLibrary
Related
I know that there are a lot of posts about this exception but non of them seemed to be helpful. I have deleted all the bin and gen folders, i have removed all library dependencies and added them again but this issue still remains.
This is the exception I get:
[dex] Pre-Dexing /home/me/dev/Workspaces/FacebookSDK/libs/android-support-v4.jar -> android-support-v4-40c394661b7676703ffc1366ddef840c.jar
[dex] Converting compiled files and external libraries into /home/me/dev/Workspaces/MyApp/bin/classes.dex...
[dx]
[dx] UNEXPECTED TOP-LEVEL EXCEPTION:
[dx] com.android.dex.DexException: Multiple dex files define Lcom/my/app/Manifest$permission;
[dx] at com.android.dx.merge.DexMerger.readSortableTypes(DexMerger.java:593)
[dx] at com.android.dx.merge.DexMerger.getSortedTypes(DexMerger.java:551)
[dx] at com.android.dx.merge.DexMerger.mergeClassDefs(DexMerger.java:532)
[dx] at com.android.dx.merge.DexMerger.mergeDexes(DexMerger.java:169)
[dx] at com.android.dx.merge.DexMerger.merge(DexMerger.java:187)
[dx] at com.android.dx.command.dexer.Main.mergeLibraryDexBuffers(Main.java:439)
[dx] at com.android.dx.command.dexer.Main.runMonoDex(Main.java:287)
[dx] at com.android.dx.command.dexer.Main.run(Main.java:230)
[dx] at com.android.dx.command.dexer.Main.main(Main.java:199)
[dx] at com.android.dx.command.Main.main(Main.java:103)
[dx]
could be something with the manifest merger?
didn't find anything unusual in my manifests files (app and libraries etc..)
App compiles and works when built and launched from eclipse.
Any ideas?
Thanks!
Consider showing your AndroidManifest.xml and build.gradle files here.
This problem is mainly because you are trying to compile two modules (mainly app and library) with same package-name for your app.
Try to change your package-name for a while, to see if that's the case.
Also this problem has been seen when libraries are added more than one time accidently. Try to see how you're compiling the libraries.
I have a problem.
I have an application builded with monodroid libraries.
Version of android sdk 4.0.3 (API level 15), GoogleAdMobAdsSdk v.6.4.1.
I made separated project to import adsdk to xamarin, add to Metadata.xml attributes. This project compiling without errors. But when i have a reference to this project from my monodroid application i get an error:
/Library/Frameworks/Mono.framework/External/xbuild/Xamarin/Android/Xamarin.Android.Common.targets: Error: Tool exited with code: 3. Output:
UNEXPECTED TOP-LEVEL ERROR:
java.lang.OutOfMemoryError: Java heap space
at com.android.dx.util.IntList.growIfNeeded(IntList.java:274)
at com.android.dx.util.IntList.add(IntList.java:217)
at com.android.dx.util.LabeledList.addLabelIndex(LabeledList.java:96)
at com.android.dx.util.LabeledList.set(LabeledList.java:184)
at com.android.dx.rop.code.BasicBlockList.set(BasicBlockList.java:77)
at com.android.dx.ssa.back.SsaToRop.convertBasicBlocks(SsaToRop.java:260)
at com.android.dx.ssa.back.SsaToRop.convert(SsaToRop.java:124)
at com.android.dx.ssa.back.SsaToRop.convertToRopMethod(SsaToRop.java:70)
at com.android.dx.ssa.Optimizer.optimize(Optimizer.java:102)
at com.android.dx.ssa.Optimizer.optimize(Optimizer.java:73)
at com.android.dx.dex.cf.CfTranslator.processMethods(CfTranslator.java:273)
at com.android.dx.dex.cf.CfTranslator.translate0(CfTranslator.java:134)
at com.android.dx.dex.cf.CfTranslator.translate(CfTranslator.java:87)
at com.android.dx.command.dexer.Main.processClass(Main.java:487)
at com.android.dx.command.dexer.Main.processFileBytes(Main.java:459)
at com.android.dx.command.dexer.Main.access$400(Main.java:67)
at com.android.dx.command.dexer.Main$1.processFileBytes(Main.java:398)
at com.android.dx.cf.direct.ClassPathOpener.processArchive(ClassPathOpener.java:245)
at com.android.dx.cf.direct.ClassPathOpener.processOne(ClassPathOpener.java:131)
at com.android.dx.cf.direct.ClassPathOpener.process(ClassPathOpener.java:109)
at com.android.dx.command.dexer.Main.processOne(Main.java:422)
at com.android.dx.command.dexer.Main.processAllFiles(Main.java:333)
at com.android.dx.command.dexer.Main.run(Main.java:209)
at com.android.dx.command.dexer.Main.main(Main.java:174)
at com.android.dx.command.Main.main(Main.java:91)
(MyMegaMonoDroidApplication)
Where is my error?
ThnX.
Please specify the Java Heap Size = 1G (or 512M might help you).
Here is how to do that for Xamarin Studio https://stackoverflow.com/a/24833518/883738
In Visual Studio you should do that in the Android project properties
When I try to compile (not execute) one of my projects, I recently get the following error:
Tool /usr/bin/java execution started with arguments: -jar /Applications/android-sdk-mac_x86/platform-tools/lib/dx.jar --no-strict --dex --output=obj/Debug/android/bin/classes.dex obj/Debug/android/bin/classes /Developer/MonoAndroid/usr/lib/mandroid/platforms/android-8/mono.android.jar FlurryAnalytics/Jars/FlurryAgent.jar Jars/android-support-v4.jar
UNEXPECTED TOP-LEVEL ERROR:
java.lang.OutOfMemoryError: Java heap space
at com.android.dx.rop.code.RegisterSpecSet.<init>(RegisterSpecSet.java:49)
at com.android.dx.rop.code.RegisterSpecSet.mutableCopy(RegisterSpecSet.java:383)
at com.android.dx.ssa.LocalVariableInfo.mutableCopyOfStarts(LocalVariableInfo.java:169)
at com.android.dx.ssa.LocalVariableExtractor.processBlock(LocalVariableExtractor.java:104)
at com.android.dx.ssa.LocalVariableExtractor.doit(LocalVariableExtractor.java:90)
at com.android.dx.ssa.LocalVariableExtractor.extract(LocalVariableExtractor.java:56)
at com.android.dx.ssa.SsaConverter.convertToSsaMethod(SsaConverter.java:50)
at com.android.dx.ssa.Optimizer.optimize(Optimizer.java:99)
at com.android.dx.ssa.Optimizer.optimize(Optimizer.java:73)
at com.android.dx.dex.cf.CfTranslator.processMethods(CfTranslator.java:273)
at com.android.dx.dex.cf.CfTranslator.translate0(CfTranslator.java:134)
at com.android.dx.dex.cf.CfTranslator.translate(CfTranslator.java:87)
at com.android.dx.command.dexer.Main.processClass(Main.java:487)
at com.android.dx.command.dexer.Main.processFileBytes(Main.java:459)
at com.android.dx.command.dexer.Main.access$400(Main.java:67)
at com.android.dx.command.dexer.Main$1.processFileBytes(Main.java:398)
at com.android.dx.cf.direct.ClassPathOpener.processArchive(ClassPathOpener.java:245)
at com.android.dx.cf.direct.ClassPathOpener.processOne(ClassPathOpener.java:131)
at com.android.dx.cf.direct.ClassPathOpener.process(ClassPathOpener.java:109)
at com.android.dx.command.dexer.Main.processOne(Main.java:422)
at com.android.dx.command.dexer.Main.processAllFiles(Main.java:333)
at com.android.dx.command.dexer.Main.run(Main.java:209)
at com.android.dx.command.dexer.Main.main(Main.java:174)
at com.android.dx.command.Main.main(Main.java:91)
Other projects build as expected. I think I need to increase the heap size for this java build step? But how?
There is an option in Xamarin Studio to increase the Java Heap Size.
Project Options -> Android Build -> Advanced -> Java Heap Size.
This suggestion did the trick:
$ export _JAVA_OPTIONS="-Xmx1g"
$ /Applications/MonoDevelop.app/Contents/MacOS/MonoDevelop
I have a few jar files in my project. Flurry, Maps and Newtonsoft... aparently this is enough to bomb the build.
Thanks to the awesome Xamarin Support team for their quick response and pointing out the solution! They are working on reducing the needed memory footprint for external jars.
I am trying to run Emma on the tests for an Android project that is a combination of Java and C/JNI code. The build and tests work fine, but whenever I add emma, I get a mysterious exception. I'm using the Android SDK v20.1 and NDK r8b.
The project is here, its an Android library project:
https://github.com/guardianproject/IOCipher
and the tests are here:
https://github.com/guardianproject/IOCipherTests
The build.xml file is generated using android update test-project. Running ant clean debug install test works everytime while ant clean emma debug install test triggers the exception:
here's the exception:
-dex:
[dex] Converting compiled files and external libraries into /var/lib/jenkins/workspace/IOCipherTests/IOCipherTests/bin/classes.dex...
[dx]
[dx] EXCEPTION FROM SIMULATION:
[dx] local variable type mismatch: attempt to set or access a value of type int using a local variable of type info.guardianproject.libcore.io.ErrnoException. This is symptomatic of .class transformation tools that ignore local variable information.
[dx]
[dx] ...at bytecode offset 0000002e
[dx] locals[0000]: Linfo/guardianproject/iocipher/File;
[dx] locals[0001]: Linfo/guardianproject/iocipher/FileDescriptor;
[dx] locals[0002]: <invalid>
[dx] locals[0003]: <invalid>
[dx] locals[0004]: <invalid>
[dx] locals[0005]: [Z
[dx] stack[top0]: int{0x00000001 / 1}
[dx] ...while working on block 002c
[dx] ...while working on method createNewFile:()Z
[dx] ...while processing createNewFile ()Z
[dx] ...while processing info/guardianproject/iocipher/File.class
[dx]
[dx] 1 error; aborting
BUILD FAILED
/opt/android-sdk/tools/ant/build.xml:850: The following error occurred while executing this line:
/opt/android-sdk/tools/ant/build.xml:852: The following error occurred while executing this line:
/opt/android-sdk/tools/ant/build.xml:864: The following error occurred while executing this line:
/opt/android-sdk/tools/ant/build.xml:266: null returned: 1
I was getting the same error. In my project we had a unit test app in one project, which wrapped another project containing the unit tests themselves. Both projects held references to my SDK which, as chaitanya suggested, was causing emma to instrument the SDK code twice. By removing the reference to the SDK in the unit test project I was able to resolve the error.
I build the Android APK project from the command line (without ant, but with some help of CMake. I guess this is not important here) and I met the same error, two things helped me:
From here, I got the info that "If you instrument class files that have local variable debug information in them emma does not correctly maintain the local variable table. This will cause an error when you try to convert the class files for Android. The workaround for this to compile the java classes with only line and source debug information, not local information.", so I add a flag to java compiler-g:{lines,source}
I also excluded Emma classes itself from instrumentation. My instrumentation command is java -cp emma/emma_device.jar emma instr -ix -*.test.*,-com.google.android.*,-com.vladium.* -m overwrite -cp ${CMAKE_JAVA_TARGET_OUTPUT_DIR}. Pay attention to -ix -com.vladium.* parameter, this excludes Emma classes
I have a static java library(classes.jar) file which has source code common to a Android Library Project and the dependent app which is calling this Android Library project.
I'm using ant env to compile the code on linux machine.
But when I include this jar file under libs folders of both ALP and App, it gives the following compilation error :
[dex] Converting compiled files and external libraries into classes.dex...
[dx]
[dx] UNEXPECTED TOP-LEVEL EXCEPTION:
[dx] java.lang.IllegalArgumentException: already added: Lcom/android/test/ProgramCache;
[dx] at com.android.dx.dex.file.ClassDefsSection.add(ClassDefsSection.java:123)
[dx] at com.android.dx.dex.file.DexFile.add(DexFile.java:163)
[dx] at com.android.dx.command.dexer.Main.processClass(Main.java:486)
[dx] at com.android.dx.command.dexer.Main.processFileBytes(Main.java:455)
[dx] at com.android.dx.command.dexer.Main.access$400(Main.java:67)
[dx] at com.android.dx.command.dexer.Main$1.processFileBytes(Main.java:394)
[dx] at com.android.dx.cf.direct.ClassPathOpener.processArchive(ClassPathOpener.java:245)
[dx] at com.android.dx.cf.direct.ClassPathOpener.processOne(ClassPathOpener.java:131)
[dx] at com.android.dx.cf.direct.ClassPathOpener.process(ClassPathOpener.java:109)
[dx] at com.android.dx.command.dexer.Main.processOne(Main.java:418)
[dx] at com.android.dx.command.dexer.Main.processAllFiles(Main.java:329)
[dx] at com.android.dx.command.dexer.Main.run(Main.java:206)
[dx] at com.android.dx.command.dexer.Main.main(Main.java:174)
[dx] at com.android.dx.command.Main.main(Main.java:95)
[dx] 1 error; aborting
How would I solve this problem of common jar?
Hopefully I won't mix up rules about building android projects in eclipse with building projects in ant with the android toolchain... (And with any luck, you won't have to do both like I do :))
Any jar files in the /libs folders of android shared libraries are automatically included by the command line android build tools. While I can't remember if they are copied on disk, or only added to the build path during compilation, it should suffice to simply remove the jar from App/libs.
Another word of advice when dealing with this problem, ant clean early and often. Its very easy to accidentally build some classes into one of your project jars and then have conflicts later.