jar-Binding of ActionBarSherlock for Mono for Android - android

I'like to bind the jar-library of ActionBarSherlock in my Mono For Android project. I am reverencing to this documentation: http://docs.xamarin.com/android/tutorials/Binding_a_Java_Library_(.jar)
I have successfully bound android-support-v4.jar which is needed by ActionBarSherlock. But when I try to compile actionbarsherlock.jar, it gives me the following error message:
Target ResolveLibraryProjects:
Skipping target "ResolveLibraryProjects" because it has no inputs.
Target _ResolveMonoAndroidSdks:
MonoAndroid Tools: C:\Program Files (x86)\MSBuild\Novell\
MonoAndroid Framework: C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\MonoAndroid\v2.2\;C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\MonoAndroid\v1.0\
Android SDK: C:\Program Files (x86)\Android\android-sdk\
Java SDK: C:\Program Files (x86)\Java\jdk1.6.0_31\
Target ExportJarToXml:
SourceJars:
Jars\actionbarsherlock.jar
ReferenceJars:
Jars\android-support-v4.jar
C:\Program Files (x86)\Java\jdk1.6.0_31\bin\java.exe -jar "C:\Program Files (x86)\MSBuild\Novell\jar2xml.jar" --jar=C:\Users\assrock\Documents\JavaBind\JavaBind\Jars\actionbarsherlock.jar --ref="C:\Program Files (x86)\Android\android-sdk\platforms\android-8\android.jar" --out=C:\Users\assrock\Documents\JavaBind\JavaBind\obj\Release\api.xml --ref=C:\Users\assrock\Documents\JavaBind\JavaBind\Jars\android-support-v4.jar
Couldn't load class com/actionbarsherlock/internal/ActionBarSherlockNative$ActionModeCallbackWrapper
Couldn't load class com/actionbarsherlock/internal/app/ActionBarWrapper$TabWrapper
Couldn't load class com/actionbarsherlock/internal/app/ActionBarWrapper
Couldn't load class com/actionbarsherlock/internal/view/ActionProviderWrapper
Couldn't load class com/actionbarsherlock/internal/view/menu/MenuItemWrapper$1
Exception in thread "main" java.lang.NoClassDefFoundError: com/actionbarsherlock/R
at java.lang.Class.getDeclaringClass(Native Method)
at jar2xml.JavaClass.getConstructorParameterOffset(JavaClass.java:149)
at jar2xml.JavaClass.appendCtor(JavaClass.java:138)
at jar2xml.JavaClass.appendToDocument(JavaClass.java:462)
at jar2xml.JavaPackage.appendToDocument(JavaPackage.java:66)
at jar2xml.Start.main(Start.java:157)
Caused by: java.lang.ClassNotFoundException: com.actionbarsherlock.R
at java.net.URLClassLoader$1.run(URLClassLoader.java:202)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
at java.lang.ClassLoader.loadClass(ClassLoader.java:247)
... 6 more
C:\Program Files (x86)\MSBuild\Novell\Xamarin.Android.Bindings.targets(170,5): error MSB6006: "java.exe" exited with code 1.
Task "JarToXml" execution -- FAILED
Done building target "ExportJarToXml" in project "C:\Users\assrock\Documents\JavaBind\JavaBind\JavaBind.csproj".-- FAILED
Done building project "C:\Users\assrock\Documents\JavaBind\JavaBind\JavaBind.csproj".-- FAILED
Build FAILED.
Warnings:
C:\Program Files (x86)\MSBuild\Novell\Xamarin.Android.Bindings.targets(40,11): warning MSB4011: There is a circular reference involving the import of file "c:\Windows\Microsoft.NET\Framework\v4.0.30319\Microsoft.CSharp.Targets". This file may have been imported more than once, or you may have attempted to import the main project file. All except the first instance of this file will be ignored.
Errors:
C:\Users\assrock\Documents\JavaBind\JavaBind\JavaBind.csproj (Build) ->
C:\Program Files (x86)\MSBuild\Novell\Xamarin.Android.Bindings.targets (ExportJarToXml target) ->
C:\Program Files (x86)\MSBuild\Novell\Xamarin.Android.Bindings.targets(170,5): error MSB6006: "java.exe" exited with code 1.
1 Warning(s)
1 Error(s)
Time Elapsed 00:00:00.4730270
--------------------- Fertig ---------------------
Build: 1 Fehler, 0 Warnungen
For the android-support-v4.jar I found these xml-files and put them in the Transforms directory:
EnumFields.xml
<enum-field-mappings>
<mapping jni-class="android/support/v4/app/FragmentActivity$FragmentTag" clr-enum-type="Android.Support.V4.App.FragmentTagType">
<field jni-name="Fragment_id" clr-name="Id" value="1" />
<field jni-name="Fragment_name" clr-name="Name" value="0" />
<field jni-name="Fragment_tag" clr-name="Tag" value="2" />
</mapping>
</enum-field-mappings>
EnumMethods.xml
<enum-method-mappings>
<mapping jni-class="android/support/v4/app/Fragment$SavedState">
<method jni-name="writeToParcel" parameter="p1" clr-enum-type="Android.OS.ParcelableWriteFlags" />
<method jni-name="writeToParcel" parameter="flags" clr-enum-type="Android.OS.ParcelableWriteFlags" />
</mapping>
</enum-method-mappings>
Metadata.xml
<metadata>
<remove-node path="/api/package[#name='android.support.v4.app']/class[#name='BackStackState']" />
<remove-node path="/api/package[#name='android.support.v4.app']/class[#name='FragmentState']" />
<remove-node path="/api/package[#name='android.support.v4.app']/class[#name='FragmentManagerState']" />
<remove-node path="/api/package[#name='android.support.v4.widget']/class[#name='CursorAdapter']/implements[#name='android.support.v4.widget.CursorFilter.CursorFilterClient']" />
<remove-node path="/api/package[#name='android.support.v4.widget']/class[#name='CursorAdapter']/field[#name='mCursorFilter']" />
<remove-node path="/api/package[#name='android.support.v4.content']/class[#name='AsyncTaskLoader.LoadTask']" />
<!-- FIXME:
This method is an override of another method in the base types.
The base method expects JLO, but this method returns Cursor.
So we somehow have to fill the gap between them.
-->
<remove-node path="/api/package[#name='android.support.v4.content']/class[#name='CursorLoader']/method[#name='loadInBackground']" />
<remove-node path="/api/package[#name='android.support.v4.view.accessibility']/class[#name='AccessibilityNodeInfoCompat.AccessibilityNodeInfoIcsImpl']" />
<remove-node path="/api/package[#name='android.support.v4.widget']/class[#name='CursorAdapter.ChangeObserver']" />
<remove-node path="/api/package[#name='android.support.v4.view.accessibility']/class[#name='AccessibilityNodeInfoCompat.AccessibilityNodeInfoIcsImpl']" />
<remove-node path="/api/package[#name='android.support.v4.view.accessibility']/class[#name='AccessibilityNodeInfoCompat.AccessibilityNodeInfoStubImpl']" />
<remove-node path="/api/package[#name='android.support.v4.view']/interface[#name='ViewPager.OnAdapterChangeListener']" />
<attr path="/api/package[#name='android.support.v4.app']/class[#name='LoaderManager']/method[#name='initLoader']/parameter[#name='p2']" name="type">android.support.v4.app.LoaderManager.LoaderCallbacks</attr>
<attr path="/api/package[#name='android.support.v4.app']/class[#name='LoaderManager']/method[#name='initLoader']/parameter[#name='callback']" name="type">android.support.v4.app.LoaderManager.LoaderCallbacks</attr>
<attr path="/api/package[#name='android.support.v4.app']/class[#name='LoaderManager']/method[#name='initLoader']" name="return">android.support.v4.content.Loader</attr>
<attr path="/api/package[#name='android.support.v4.app']/class[#name='LoaderManager']/method[#name='restartLoader']/parameter[#name='p2']" name="type">android.support.v4.app.LoaderManager.LoaderCallbacks</attr>
<attr path="/api/package[#name='android.support.v4.app']/class[#name='LoaderManager']/method[#name='restartLoader']/parameter[#name='callback']" name="type">android.support.v4.app.LoaderManager.LoaderCallbacks</attr>
<attr path="/api/package[#name='android.support.v4.app']/class[#name='LoaderManager']/method[#name='restartLoader']" name="return">android.support.v4.content.Loader</attr>
</metadata>

ActionBarSherlock includes UI elements, styles, and other things that can't be compiled into a JAR file. There is a note about this on the ActionBarSherlock FAQ.
Q: Why is ActionBarSherlock a library project whereas the original compatibility library is only a .jar?
A: The custom action bar implementation within ActionBarSherlock relies on styles, themes, layouts, and drawables in order to display properly. Due to the limitations of Android and .jar files, this currently can not be accomplished any other way.
Edit: There is some additional information about trying to share resources across library projects in Mono for Android at this link: http://mono-for-android.1047100.n5.nabble.com/Resources-from-a-Library-Project-td4657828.html. Short answer is it doesn't look possible at the moment.

I believe I have successfully bound ActionBarSherlock in Mono for Android.
You need to package the java files as a JAR file but without the resources and without the R java class files. Before you package the files make sure that you check the box in Android settings that says "Is Library" so that the resource IDs are not created as constants and inlined in your compiled java classes.
Once you have done this you can use the latest version of Mono for Android to bind the JAR file.
Resources need to be copied separately from the JAR file and placed directly in the main android application project. Unfortunately, at the present time there is no way to isolate the resources in a separate library project when using Mono for Android, but I expect that will change soon.
Finally, you need to edit your C-Sharp project file so that it automatically creates a new version of the com.actionbarsherlock.R java class file each time you rebuild. This is required to keep all your resource IDs in sync.
I may have missed a step or two but those are the most important ones.
Please see my blog post for more information and a download link with source code:
http://www.craigsprogramming.com/2012/07/actionbarsherlock-with-mono-for-android.html

This may seem like a sledgehammer approach, but will likely solve your problem...
I would suggest building using Maven, which handles these dependencies much better. You will be able to reference the ActionBarSherlock project in your POM, and MVN will manage the dependancies for you.
I can confirm the original answer as correct as well - there is a limitation to including JAR files that contain layout resources.

Looks like Xamarin solved ActionBarSherlock bound issue
https://bugzilla.xamarin.com/show_bug.cgi?id=6186
This fix has included in 4.2.5 which is available on alpha channel now.

Related

Unity3d Admob integration breaks Android Build: "D8: Program type already present: android.support.customtabs.ICustomTabsCallback"

I am developing an Android Game and for a week now, I have tried my best to implement AdMob with Mediation. It works fine in the Editor, but when I build, it throws the error mentioned below. I did try to implement multiple other plugins and they built successfully, but crashed on launch (also tried with just their sample app implementations in new projects).
After a lot of digging around, I have a hypothesis that Facebook needs some aars that Admob need, but cannot use the latest version of it (I have tried latest FB SDK versions to no avail as well). Here are some things I noticed:
Notice that CustomTabs is present here. I tried deleting these classes but then build failed with another error
Some conflicting dependencies were found.
The following dependency versions were modified:
com.android.support:appcompat-v7:25.3.1 --> com.android.support:appcompat-v7:27.0.2#aar
com.android.support:cardview-v7:25.3.1 --> com.android.support:cardview-v7:27.0.2#aar
com.android.support:customtabs:25.3.1 --> com.android.support:customtabs:27.0.2#aar
com.android.support:support-v4:25.3.1 --> com.android.support:support-v4:27.0.2#aar
This is the AndroidResolverDependencies.xml file in ProjectSettings Dir.
com.android.support:appcompat-v7:25.3.1
com.android.support:cardview-v7:25.3.1
com.android.support:customtabs:25.3.1
com.android.support:support-v4:25.3.1
com.facebook.android:facebook-core:[5,6)
com.facebook.android:facebook-login:[5,6)
com.facebook.android:facebook-share:[5,6)
com.google.ads.mediation:unity:3.1.0.0
com.google.android.gms:play-services-ads:18.0.0
com.parse.bolts:bolts-android:1.4.0
com.unity3d.ads:unity-ads:3.1.0
Assets/Plugins/Android/android.arch.core.common-1.0.0.jar
Assets/Plugins/Android/android.arch.lifecycle.common-1.0.3.jar
Assets/Plugins/Android/android.arch.lifecycle.runtime-1.0.3.aar
Assets/Plugins/Android/androidx.annotation.annotation-1.0.0.jar
Assets/Plugins/Android/androidx.arch.core.core-common-2.0.0.jar
Assets/Plugins/Android/androidx.arch.core.core-runtime-2.0.0.aar
Assets/Plugins/Android/androidx.asynclayoutinflater.asynclayoutinflater-1.0.0.aar
Assets/Plugins/Android/androidx.browser.browser-1.0.0.aar
Assets/Plugins/Android/androidx.collection.collection-1.0.0.jar
Assets/Plugins/Android/androidx.coordinatorlayout.coordinatorlayout-1.0.0.aar
Assets/Plugins/Android/androidx.core.core-1.0.0.aar
Assets/Plugins/Android/androidx.cursoradapter.cursoradapter-1.0.0.aar
Assets/Plugins/Android/androidx.customview.customview-1.0.0.aar
Assets/Plugins/Android/androidx.documentfile.documentfile-1.0.0.aar
Assets/Plugins/Android/androidx.drawerlayout.drawerlayout-1.0.0.aar
Assets/Plugins/Android/androidx.fragment.fragment-1.0.0.aar
Assets/Plugins/Android/androidx.interpolator.interpolator-1.0.0.aar
Assets/Plugins/Android/androidx.legacy.legacy-support-core-ui-1.0.0.aar
Assets/Plugins/Android/androidx.legacy.legacy-support-core-utils-1.0.0.aar
Assets/Plugins/Android/androidx.lifecycle.lifecycle-common-2.0.0.jar
Assets/Plugins/Android/androidx.lifecycle.lifecycle-livedata-2.0.0.aar
Assets/Plugins/Android/androidx.lifecycle.lifecycle-livedata-core-2.0.0.aar
Assets/Plugins/Android/androidx.lifecycle.lifecycle-runtime-2.0.0.aar
Assets/Plugins/Android/androidx.lifecycle.lifecycle-viewmodel-2.0.0.aar
Assets/Plugins/Android/androidx.loader.loader-1.0.0.aar
Assets/Plugins/Android/androidx.localbroadcastmanager.localbroadcastmanager-1.0.0.aar
Assets/Plugins/Android/androidx.print.print-1.0.0.aar
Assets/Plugins/Android/androidx.slidingpanelayout.slidingpanelayout-1.0.0.aar
Assets/Plugins/Android/androidx.swiperefreshlayout.swiperefreshlayout-1.0.0.aar
Assets/Plugins/Android/androidx.versionedparcelable.versionedparcelable-1.0.0.aar
Assets/Plugins/Android/androidx.viewpager.viewpager-1.0.0.aar
Assets/Plugins/Android/com.android.support.animated-vector-drawable-27.0.2.aar
Assets/Plugins/Android/com.android.support.appcompat-v7-27.0.2.aar
Assets/Plugins/Android/com.android.support.cardview-v7-27.0.2.aar
Assets/Plugins/Android/com.android.support.customtabs-27.0.2.aar
Assets/Plugins/Android/com.android.support.support-annotations-27.0.2.jar
Assets/Plugins/Android/com.android.support.support-compat-27.0.2.aar
Assets/Plugins/Android/com.android.support.support-core-ui-27.0.2.aar
Assets/Plugins/Android/com.android.support.support-core-utils-27.0.2.aar
Assets/Plugins/Android/com.android.support.support-fragment-27.0.2.aar
Assets/Plugins/Android/com.android.support.support-media-compat-27.0.2.aar
Assets/Plugins/Android/com.android.support.support-v4-27.0.2.aar
Assets/Plugins/Android/com.android.support.support-vector-drawable-27.0.2.aar
Assets/Plugins/Android/com.facebook.android.facebook-common-5.1.0.aar
Assets/Plugins/Android/com.facebook.android.facebook-core-5.1.0.aar
Assets/Plugins/Android/com.facebook.android.facebook-login-5.1.0.aar
Assets/Plugins/Android/com.facebook.android.facebook-share-5.1.0.aar
Assets/Plugins/Android/com.google.ads.mediation.unity-3.1.0.0.aar
Assets/Plugins/Android/com.google.android.gms.play-services-ads-18.0.0.aar
Assets/Plugins/Android/com.google.android.gms.play-services-ads-base-18.0.0.aar
Assets/Plugins/Android/com.google.android.gms.play-services-ads-identifier-17.0.0.aar
Assets/Plugins/Android/com.google.android.gms.play-services-ads-lite-18.0.0.aar
Assets/Plugins/Android/com.google.android.gms.play-services-basement-17.0.0.aar
Assets/Plugins/Android/com.google.android.gms.play-services-gass-18.0.0.aar
Assets/Plugins/Android/com.google.android.gms.play-services-measurement-base-17.0.0.aar
Assets/Plugins/Android/com.google.android.gms.play-services-measurement-sdk-api-17.0.0.aar
Assets/Plugins/Android/com.google.zxing.core-3.3.3.jar
Assets/Plugins/Android/com.parse.bolts.bolts-android-1.4.0.jar
Assets/Plugins/Android/com.parse.bolts.bolts-applinks-1.4.0.jar
Assets/Plugins/Android/com.parse.bolts.bolts-tasks-1.4.0.jar
Assets/Plugins/Android/com.unity3d.ads.unity-ads-3.1.0.aar
<settings>
<setting name="androidAbis" value="armeabi-v7a,x86" />
<setting name="bundleId" value="com.pratyaksh.cosmicballs" />
<setting name="explodeAars" value="True" />
<setting name="gradleBuildEnabled" value="True" />
<setting name="gradleTemplateEnabled" value="False" />
<setting name="installAndroidPackages" value="True" />
<setting name="packageDir" value="Assets\Plugins\Android" />
<setting name="patchAndroidManifest" value="True" />
<setting name="patchMainTemplateGradle" value="True" />
<setting name="projectExportEnabled" value="False" />
<setting name="useJetifier" value="False" />
</settings>
</dependencies>
Smaller Portions from error log
CommandInvokationFailure: Gradle build failed.
E:\UnityEditor\2019.1.0f2\Editor\Data\PlaybackEngines\AndroidPlayer/Tools\OpenJDK\Windows\bin\java.exe -classpath "E:\UnityEditor\2019.1.0f2\Editor\Data\PlaybackEngines\AndroidPlayer\Tools\gradle\lib\gradle-launcher-4.6.jar" org.gradle.launcher.GradleMain "-Dorg.gradle.jvmargs=-Xmx4096m" "assembleRelease"
stderr[
D8: Program type already present: android.support.customtabs.ICustomTabsCallback
FAILURE: Build failed with an exception.
What went wrong:
Execution failed for task ':transformDexArchiveWithExternalLibsDexMergerForRelease'.
com.android.builder.dexing.DexArchiveMergerException: Error while merging dex archives:
.
.
//SHORTENED FOR STACKOVERFLOW
.
.
.
:transformClassesWithDexBuilderForRelease
C:\Users\TehBlindNutSack.gradle\caches\transforms-1\files-1.1\facebook-android-wrapper-7.17.0.aar\4bb1132b85935d425bf3b80edd9162a8\jars\classes.jar: D8: Interface com.facebook.applinks.AppLinkData$CompletionHandler not found. It's needed to make sure desugaring of com.facebook.unity.FB$2 is correct. Desugaring will assume that this interface has no default method.
C:\Users\TehBlindNutSack\.gradle\caches\transforms-1\files-1.1\facebook-android-wrapper-7.17.0.aar\4bb1132b85935d425bf3b80edd9162a8\jars\classes.jar: D8: Typecom.facebook.applinks.AppLinkDatawas not found, it is required for default or static interface methods desugaring ofvoid com.facebook.unity.FB.FetchDeferredAppLinkData(java.lang.String)`
:transformDexArchiveWithExternalLibsDexMergerForRelease FAILED
Please, if someone could help me get it right, it would mean a world to me.
Sorry for bad formatting.
Edit: Steps to reproduce:
1. Create a new Unity(2019.1.0f2) Project with android build support
2. Add FB SDK
3. add GoogleMobileAds SDK
4. Build
When you're using GooglePlayResolver you'll be getting new androidx. files. Which could be in conflict with com.android.support. files
Try to do this:
Assets -> GooglePlayResolver -> Android Resolver -> Settings -> Set Jetiffier On
Force Resolve.
Be sure to use the latest:
https://github.com/googlesamples/unity-jar-resolver/releases/tag/v1.2.121
Check this discussion for more info.
https://github.com/googlesamples/unity-jar-resolver/issues/145
I found solutions. there are library files duplicates, see directory and see library files make it as I did. Android and iOS library should be set for each platform.
Download SDK from "https://developers.facebook.com/docs/unity/"
Open SDK directory. there are duplicates. So make a library for each platform.
Set proper platform for iOS and Android.
It works and I tested on Unity 2019.1.0f2. facebookSDK has problem with compile. they made trap.
I have a good news and a bad news.
Bad news First: None of the above solutions worked for me.
Good News: I installed 2019.1.08f and it threw the same error, but with a longer log. I went through the log and found the exact files causing the collision: androidx.browser.browser-1.0.0.aar and androidx.core.core-1.0.0.aar.
I just went into them, opened Classes.jar and deleted Android directory in both the aars' jars.
Build and Run...Voila. (At least for now).
Will update here if another issue arises.
Thank you Brian, for Taking the time to test it and answering the question.

Generating android code coverage though changes in build.xml and ant.properties

I have been trying to generate android code coverage for my android test project which tests a android project which includes a external jar. When I run command
ant emma install debug test
it shows coverage of only the android project but does not include the package and functions of the external jar included.
As per my researches I have found that some changes should be done in ant.properties file and emma report tag in build.xml.
Any suggestions are most welcome.
[Edit]
On furthur study, I went through a blog which says enter the variable
tested.android.library.source.dir="path to external jars" in ant.properties
and same variable should be added in report sourcepath as
<emma>
<report sourcepath="${tested.project.source.absolute.dir}:${tested.project.lib.source.path.value}:${tested.android.library.source.dir}" verbosity="${verbosity}">
<!-- TODO: report.dir or something like should be introduced if necessary -->
<infileset file="${out.absolute.dir}/coverage.ec" />
<infileset file="${tested.project.out.absolute.dir}/coverage.em" />
<!-- TODO: reports in other, indicated by user formats -->
<html outfile="${out.absolute.dir}/coverage.html" />
</report>
</emma>
But still the coverage is not showing functions and package of External jar.
I wanted to know that my jars are not in the android test project but in the android project which is tested. So how to give path to those external jars in ant.properties of the test project.
I am also working on the same from quite some time.
Refer to code coverage reports for library projects
External jars coverage support is in ADT-r20.
I can only point to the direction I am working.
I am working on modifying build.xml inside ant :
<!-- This is macro that enable passing variable list of external jar files to ApkBuilder
Example of use:
<package-helper>
<extra-jars>
<jarfolder path="my_jars" />
<jarfile path="foo/bar.jar" />
<jarfolder path="your_jars" />
</extra-jars>
</package-helper> -->
<macrodef name="package-helper">
<element name="extra-jars" optional="yes" />
<sequential>
<apkbuilder
outfolder="${out.absolute.dir}"
resourcefile="${resource.package.file.name}"
apkfilepath="${out.packaged.file}"
debugpackaging="${build.is.packaging.debug}"
debugsigning="${build.is.signing.debug}"
verbose="${verbose}"
hascode="${manifest.hasCode}"
previousBuildType="${build.last.is.packaging.debug}/${build.last.is.signing.debug}"
buildType="${build.is.packaging.debug}/${build.is.signing.debug}">
<dex path="${intermediate.dex.file}"/>
<sourcefolder path="${source.absolute.dir}"/>
<jarfile refid="project.all.jars.path" />
<nativefolder path="${native.libs.absolute.dir}" />
<nativefolder refid="project.library.native.folder.path" />
<extra-jars/>
</apkbuilder>
</sequential>
</macrodef>
I have no luck till yet.
After lots of searching and trying , finally got the package of my External jar in my Main project.
Just entered tested.android.library.source.dir in ant.properties and build.xml
ant.properties: tested.android.library.source.dir="Path to libs folder of main project where jars are present"
Build.xml : Under emma tag in report tag add this variable seperated by colon.
Now go to command prompt and run
In Main Project :android update project -p .
In Test Project: android update test-project -m "Path of main project" -p .
Now copy test target from build.xml (sdk/tools/ant/build.xml) and paste it in build.xml of test project above the line
<import file="${sdk.dir}/tools/ant/build.xml" />
Dont Forget to Change Version Tag to
Now Again open command prompt and run:
In Main Project: ant emma debug install
In Test Project: ant emma debug install test
Your Code coverage report generated will contain the package of the external jar
I struggled with this for 2 days and eventually figured it out. The code snippet in the first post only generates instrument report from emma metadatafile and runtime coverage file but does not perform instrumentation on jar. To instrument the code you will have to manipulate the byte code, like how android ant build.xml target does it. Take a look at the element nested in <-compile> and you will see comment like it is only instrumenting class files. To instrument the jars add a classpath like element to the jars along with path to class.
Emma Documentation: http://emma.sourceforge.net/reference/ch02s03s02.html
<emma enabled="${emma.enabled}" >
<instr mode="fullcopy"
outdir="${out.instr.dir}"
merge="no"
filter="${emma.filter}">
<instrpath>
<fileset dir="${out.dir}" includes="**/*.jar" />
</instrpath>
</instr>
</emma>
In Android's build.xml. One just have to delete instrpath attribute and make it look like the example above.
756 <emma enabled="true">
757 <instr verbosity="${verbosity}"
758 mode="overwrite"
759 instrpath="${out.absolute.dir}/classes"
760 outdir="${out.absolute.dir}/classes"
761 metadatafile="${emma.coverage.absolute.file}">
762 <filter excludes="${emma.default.filter}" />
763 <filter value="${emma.filter}" />
764 </instr>
765 </emma>
So something like this: (pardon the line#s)
756 <emma enabled="true">
757 <instr verbosity="${verbosity}"
758 mode="overwrite"
760 outdir="${out.absolute.dir}/classes"
761 metadatafile="${emma.coverage.absolute.file}">
759 <instrpath>
759 <pathelement path="${out.absolute.dir}/classes"/>
759 <fileset dir="${you-class-path}"/>
759 <include name="**/*.jar"/>
759 </fileset>
759 </instrpath>
762 <filter excludes="${emma.default.filter}" />
763 <filter value="${emma.filter}" />
764 </instr>
765 </emma>

Use JAXB (xjc) generated classes in android

I am using a Rest-Webservice in Android. The Web Service could handle JSON and XML, the API is described as an XSD. So I used JAXB to generate classes from the XSD and then I used jackson JSON processor to generate JSON from my instances.
The problem is, that JAXB (xjc) generates classes with JAXB annotations and Android can't handle those. I tried to add the jaxb-api.jar to my android project but the Dalvik won't use core classes.
For my first implementation I manually removed the annotations. But now the XSD was updated and I don't want to do this every time this happens.
Do you have any idea how to handle this problem in a better way? Is there a possibility to use jaxb/xjc without annotations or is there another code generater that could do this? Do you know an easy way to remove annotations from java classes (even if they are printed in multiple lines)? Is there a project setting for Android Eclipse projects, that makes the dalvik to allow core libs?
thx, cathixx
I had to do some extra researching to make cathixx's answer work since I'm new to Ant, so I'll share this to help others.
These instructions will take Java files with code like:
import javax.xml.bind.annotation.XmlElement;
#XmlRootElement
public class Response {...
...and comment these occurrences out, so it looks like:
/*import javax.xml.bind.annotation.XmlElement;*/
/*#XmlRootElement*/
public class Response {...
First, create a file build.xml (or whatever you want to call it - must be .xml) in a new Eclipse project (a "General" project is fine).
Then, add the following text to the build.xml file:
<?xml version="1.0"?>
<project
name="CommentOutXmlAnnotations"
basedir="."
default="commentOutXmlAnnotations" >
<!-- This Ant script comments out the following lines from the Java files in this directory:
import javax.xml.bind.annotation.*;
#Xml*
-->
<target
name="commentOutXmlAnnotations"
description="Run" >
<replaceregexp
byline="false"
flags="g" >
<regexp pattern="(#Xml[A-Za-z0-9]+(\([^)]+\))?|import javax\.xml\.bind\.annotation\.[A-Za-z0-9.]+;)[ \t]*(\r?\n)" />
<substitution expression="/*\1*/\3" />
<fileset dir="." >
<include name="*.java" />
</fileset>
</replaceregexp>
</target>
</project>
Put the *.java files you want to comment out the XML imports and annotations for in the same directory as the build.xml file.
Right-click on the build.xml file in Eclipse, and click "Run As->Ant Build".
You should see output like:
Buildfile: D:\Eclipse_Projects\StripAnnotations\build.xml
commentOutXmlAnnotations:
BUILD SUCCESSFUL
Total time: 403 milliseconds
...and the XML imports and annotations should be commented out of your files.
Done!
Note: if you want to include all *.java files in all subdirectories of the build.xml file (for example, to comment out all XML annotations/imports generated for a bunch of JAXB classes in multiple packages), change the fileset tag to:
<fileset dir="." >
<include name="**/*.java" />
</fileset>
now, I solved it by myself by commenting all annotations with the following ant script:
<replaceregexp flags="g" byline="false">
<regexp pattern="(#Xml[A-Za-z0-9]+(\([^)]+\))?|import javax\.xml\.bind\.annotation\.[A-Za-z0-9.]+;)[ \t]*(\r?\n)"/>
<substitution expression="/*\1*/\3"/>
<fileset dir="path/to/files">
<include name="*.java"/>
</fileset>
</replaceregexp>

Android build.xml renderscript doesn't support includepath

I'm running my android project using ant in order to continuously run it using Hudson. I have created my build.xml on my mac and instead of importing the generated android build.xml, I copy/pasted it in, since I have to customize some things.
It works fine on my local machine, however, when I run this on hudson, located on a server. I run into an error with the Renderscript attribute.
renderscript doesn't support the "includePath" attribute
So, I decided to take OUT that line in the xml transforming this code:
<renderscript executable="${renderscript}"
includePath="${android.renderscript.include.path}"
genFolder="${gen.absolute.dir}"
resFolder="${out.res.absolute.dir}/raw"
targetApi="${project.minSdkVersion}"
optLevel="${renderscript.opt.level}"
buildType="${build.is.packaging.debug}"
previousBuildType="${build.last.is.packaging.debug}">
<source path="${source.absolute.dir}"/>
</renderscript>
to this:
<renderscript executable="${renderscript}"
genFolder="${gen.absolute.dir}"
resFolder="${out.res.absolute.dir}/raw"
targetApi="${project.minSdkVersion}"
optLevel="${renderscript.opt.level}"
buildType="${build.is.packaging.debug}"
previousBuildType="${build.last.is.packaging.debug}">
<source path="${source.absolute.dir}"/>
</renderscript>
And then comically get this error:
RenderScriptTask's 'includePath' is required.
I'm running the same ant on both machines, downloaded the linux-specific SDK on the server, updated based on tools, platform-tools, and android-7 (the OS I'm supporting). I've run out of ideas of what the problem could be, any help or pointers would be amazing.
Thanks!
This error happened because you updated the android sdk tools to revision to 20.0.1.
renderscript requires the property includePathRefId and it's path was changed. So your code should be:
<renderscript executable="${renderscript}"
includePathRefId="android.renderscript.include.path"
genFolder="${gen.absolute.dir}"
resFolder="${out.res.absolute.dir}/raw"
targetApi="${project.minSdkVersion}"
optLevel="${renderscript.opt.level}"
buildType="${build.is.packaging.debug}"
previousBuildType="${build.last.is.packaging.debug}">
<source path="${source.absolute.dir}"/>
</renderscript>
where the includePathRefId it should be defined like this:
<path id="android.renderscript.include.path">
<pathelement location="${android.platform.tools.dir}/renderscript/include" />
<pathelement location="${android.platform.tools.dir}/renderscript/clang-include" />
</path>
This ended up happening because I had some files to be ignored via the classpath. It was a simple, but overlooked mistake.

aapt basename attribute

I upgraded my SDK to 2.3 and my build scripts start to fail. I am getting this error:
build.xml:363: aaptexec doesn't support the "basename" attribute
For the following line in my build script:
<aapt executable="${aapt}" command="package" manifest="AndroidManifest.xml" resources="${resource.absolute.dir}" assets="${asset.absolute.dir}" androidjar="${android.jar}" outfolder="${out.absolute.dir}" basename="${ant.project.name}" />
I do not know what changed in aapt but apparently basename is not there any more. Can you tell me what should I use instead?
I had similar problems when upgrading from 2.1 to 2.3 with symbolic names changing in the built in 'rules' xmls. 2.1 seemed to use ant_rules_3.xml, now SDK 2.3 uses main_rules.xml as its starting point. If, like me, you had customised your build.xml based on the targets in the rules file, you will probably find it easier to start again by creating a sample project as described in : link text
then adapting you build.xml to override some or all of the targets that are listed in main_rules.xml. (This is in the sdk\tools\ant folder). I found this process to be reasonably quick, and for simple projects the generated files worked 'out of the box' with Ant. (I did have to change the build.xml a lot for a project which contained a second source folder containing .aidl files, as the main_rules.xml couldn't cope with it)
There are two targets which refer to aapt in the main_rules.xml, it's probably this one that you need to mimic:
<target name="-package-resources">
<echo>Packaging resources</echo>
<aapt executable="${aapt}"
command="package"
versioncode="${version.code}"
debug="${build.packaging.debug}"
manifest="AndroidManifest.xml"
assets="${asset.absolute.dir}"
androidjar="${android.jar}"
apkfolder="${out.absolute.dir}"
resourcefilename="${resource.package.file.name}"
resourcefilter="${aapt.resource.filter}">
<res path="${resource.absolute.dir}" />
<!-- <nocompress /> forces no compression on any files in assets or res/raw -->
<!-- <nocompress extension="xml" /> forces no compression on specific file extensions in assets and res/raw -->
</aapt>
</target>
I think the resourcefilename is the name of the generated apk. My build scripts generate the apks and put them in the bin directory OK, without my naming the resourcefilename explicitly.
My build.properties looks like:
#-----------------------------------------------
# The ONLY reference to the project's main base
#
projectname=MapProject1.2
#
#-----------------------------------------------
workspace.dir=/dev/projects/EclipseHelios/AndroidWorkspace
ant.project.name=${projectname}
outbasebase.dir=/dev/projects/AntBuilds
base.dir=${workspace.dir}/${projectname}
common_src=/dev/projects/CommonSource121210/GridSeviceAndUseGridService
source.dir=${base.dir}/src
outbase.dir=${outbasebase.dir}/${projectname}
out.dir=${outbase.dir}/bin
key.store=c:/users/me/my-release-key.keystore
key.alias=release_alias
key.store.password=*************
key.alias.password=*************
layout.dir=${base.dir}/res/layout
(Apart from the passwords of course!)
I did comment out the projectname in the buid.xml, so that it would pick it up from the build.properties.

Categories

Resources