Xamarin (monodroid) + adMob build error - android

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

Related

Building android AOSP 4.2.2 in ubuntu 14.04 gives error

I tried to build the AOSP following the android parent site "https://source.android.com/source/building-running.html".
Steps :
a) source build/envsetup.sh
b) lunch
c) I selected "full-eng"
d) Then make -j4
I have configured the cchache as well. Some error with switch.pm also I got, then I resolved it as well but after this error I am not getting anything. I can see the userdata.img and ramdisk.img file in the out folder. I dont see the system.img file.
And it throws this error. Anythigh else I missed, let me know.
I got this error :
UNEXPECTED TOP-LEVEL EXCEPTION:
com.android.dx.util.ExceptionWithContext: Index: 1, Size: 2
at com.android.dx.util.ExceptionWithContext.withContext(ExceptionWithContext.java:46)
at com.android.dx.dex.cf.CfTranslator.processMethods(CfTranslator.java:344)
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)
Caused by: java.lang.IndexOutOfBoundsException: Index: 1, Size: 2
at java.util.ArrayList.RangeCheck(ArrayList.java:547)
at java.util.ArrayList.remove(ArrayList.java:387)
at com.android.dx.ssa.Dominators.compress(Dominators.java:136)
at com.android.dx.ssa.Dominators.eval(Dominators.java:160)
at com.android.dx.ssa.Dominators.run(Dominators.java:229)
at com.android.dx.ssa.Dominators.make(Dominators.java:90)
at com.android.dx.ssa.DomFront.run(DomFront.java:90)
at com.android.dx.ssa.SsaConverter.placePhiFunctions(SsaConverter.java:298)
at com.android.dx.ssa.SsaConverter.convertToSsaMethod(SsaConverter.java:52)
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)
... 14 more
...while processing onQueryComplete (ILjava/lang/Object;Lcom/android/internal/telephony/CallerInfo;)V
...while processing com/android/phone/CallNotifier.class
What am I missing here? Please help me out as I can am not able to proceed further then this state.
Environment :
Linux Ubuntu 14.04
JDK 1.6.0
AOSP branch for 4.2.2

How to fix "OutOfMemoryError: java heap space" while compiling MonoDroid App in MonoDevelop

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.

Android IllegalArgumentException: already added

I have created an android application that uses android-support-v4.jar.
Now when I add an android library to this project I get this error when building:
UNEXPECTED TOP-LEVEL EXCEPTION:
java.lang.IllegalArgumentException: already added: Landroid/support/v4/accessibilityservice/AccessibilityServiceInfoCompat$AccessibilityServiceInfoIcsImpl;
[2012-11-08 16:02:31 - ShoppingApp Android] Conversion to Dalvik format failed with error 1
The library I'm trying to add is Facebook SDK, which also happens to use android-support-v4.jar.
Only solution for this error I found was removing library from one of build paths, but I can't do it - all options all disabled when I select this jar.
Here is full error trace:
UNEXPECTED TOP-LEVEL EXCEPTION:
java.lang.IllegalArgumentException: already added: Landroid/support/v4/accessibilityservice/AccessibilityServiceInfoCompat$AccessibilityServiceInfoIcsImpl;
at com.android.dx.dex.file.ClassDefsSection.add(ClassDefsSection.java:123)
at com.android.dx.dex.file.DexFile.add(DexFile.java:163)
at com.android.dx.command.dexer.Main.processClass(Main.java:486)
at com.android.dx.command.dexer.Main.processFileBytes(Main.java:455)
at com.android.dx.command.dexer.Main.access$400(Main.java:67)
at com.android.dx.command.dexer.Main$1.processFileBytes(Main.java:394)
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:418)
at com.android.dx.command.dexer.Main.processAllFiles(Main.java:329)
at com.android.dx.command.dexer.Main.run(Main.java:206)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at com.android.ide.eclipse.adt.internal.build.DexWrapper.run(DexWrapper.java:180)
at com.android.ide.eclipse.adt.internal.build.BuildHelper.executeDx(BuildHelper.java:703)
at com.android.ide.eclipse.adt.internal.build.builders.PostCompilerBuilder.build(PostCompilerBuilder.java:577)
at org.eclipse.core.internal.events.BuildManager$2.run(BuildManager.java:728)
at org.eclipse.core.runtime.SafeRunner.run(SafeRunner.java:42)
at org.eclipse.core.internal.events.BuildManager.basicBuild(BuildManager.java:199)
at org.eclipse.core.internal.events.BuildManager.basicBuild(BuildManager.java:321)
at org.eclipse.core.internal.events.BuildManager.build(BuildManager.java:396)
at org.eclipse.core.internal.resources.Project$1.run(Project.java:618)
at org.eclipse.core.internal.resources.Workspace.run(Workspace.java:2344)
at org.eclipse.core.internal.resources.Project.internalBuild(Project.java:597)
at org.eclipse.core.internal.resources.Project.build(Project.java:124)
at com.android.ide.eclipse.adt.internal.project.ProjectHelper.doFullIncrementalDebugBuild(ProjectHelper.java:1000)
at com.android.ide.eclipse.adt.internal.launch.LaunchConfigDelegate.launch(LaunchConfigDelegate.java:147)
at org.eclipse.debug.internal.core.LaunchConfiguration.launch(LaunchConfiguration.java:855)
at org.eclipse.debug.internal.core.LaunchConfiguration.launch(LaunchConfiguration.java:704)
at org.eclipse.debug.internal.ui.DebugUIPlugin.buildAndLaunch(DebugUIPlugin.java:1047)
at org.eclipse.debug.internal.ui.DebugUIPlugin$8.run(DebugUIPlugin.java:1251)
at org.eclipse.core.internal.jobs.Worker.run(Worker.java:53)
[2012-11-08 16:02:31 - ShoppingApp Android] Dx 1 error; aborting
[2012-11-08 16:02:31 - ShoppingApp Android] Conversion to Dalvik format failed with error 1
The build process checks the checksum of every jar and raises this error if the jar is found twice and the jars have different checksums.
This means you have the same library twice but two different versions of the jar file, which doesn't make sense.
If you added a library project, you don't need the support library in your app, you can delete it as it is inherited from the project library.
You might want to update the jar of the support library into the library project.
Edit: you don't play with the build path anymore, your libraries folders should be "libs" and it will appear in the project as "Android dependencies". Then you remove the jar from your libs folder of your app, and maybe update the one from the library project.
This error means that you have some classes included more than once in your build. I've solved quite the same problem with mvn dependencies in eclipse by unchecking "Export maven decencies" in Project configuration/Java Build Path/Export.

Failed to build Android app (refer to both ActionBarSherlock & ViewPagerTabs) with Ant

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

Accessing common jar file from App as well as from Android Library Project

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.

Categories

Resources