Quantcast

Building a package with a jar bindings library strips the jar file from the assembly

classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Building a package with a jar bindings library strips the jar file from the assembly

Vladimir Dimitrov
Hello,

I am trying to make a jar bindings project that I need in my app.
1. I created a jar binding project.
2. Added the .jar file in the Jars folder.
3. Made it an EmbeddedJar
4. Build the project
5. Referenced the project from another project and added some logic
using the callable wrappers.

Now when I build the project I see that an assembly is generated with
the .jar file inside it as a resource.
But when I try to run in debug mode I get a
java.lang.NoClassDefFoundError exception.
I noticed that if I build an .apk, unzip it and decompile the jar
bindings assembly, the jar file is no longer in it.
So is that a bug Xamarin Android that is happening? I don't seem t find
anything on Google that may help me out.
I am using the latest beta version of Xamarin.Android.

Thanks,
  Vladimir
_______________________________________________
Monodroid mailing list
[hidden email]

UNSUBSCRIBE INFORMATION:
http://lists.ximian.com/mailman/listinfo/monodroid
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Building a package with a jar bindings library strips the jar file from the assembly

Jonathan Pryor-3
On Nov 26, 2013, at 8:27 AM, Vladimir Dimitrov <[hidden email]> wrote:

> I am trying to make a jar bindings project that I need in my app.
> 1. I created a jar binding project.
> 2. Added the .jar file in the Jars folder.
> 3. Made it an EmbeddedJar
> 4. Build the project
> 5. Referenced the project from another project and added some logic using the callable wrappers.
>
> Now when I build the project I see that an assembly is generated with the .jar file inside it as a resource.
> But when I try to run in debug mode I get a java.lang.NoClassDefFoundError exception.
> I noticed that if I build an .apk, unzip it and decompile the jar bindings assembly, the jar file is no longer in it.

This is by design, and is unrelated to your error.

Android doesn't run Java bytecode, it runs Dalvik bytecode. Consequently, .jar files on device are entirely useless, and would only serve to bloat your application size for no benefit.

Instead, what should be happening is that the .jar resource is extracted, and the .jar is then passed to dx.jar (the Dex compiler) along with all the other Java bytecode that makes up the app (compiled Android Callable Wrappers, etc.).

The important part, then, is the `classes.dex` entry within the .apk. The "sanity check" is to extract your .apk, run `dexdump classes.dex`, and see if the type you're getting a NoClassDefFoundError for is present (or not present) within classes.dex. (`dexdump` is located in the Android SDK, e.g. $ANDROID_SDK_PATH/build-tools/19.0.0/dexdump.)

Note that dexdump lists types in JNI format, e.g. you'll see "L/your/package/name/TypeName;".

If the type is missing from classes.dex, that's a problem. :-)

I would suggest cleaning everything, nuking all bin & obj directories, and rebuilding. If that doesn't fix it, please provide the diagnostic build output. In particular, you want to find `dx.jar` invocation, and double-check that your embedded .jar is listed:

        Tool /usr/bin/java execution started with arguments: -jar /opt/android/sdk/platform-tools/lib/dx.jar --no-strict --dex --output=obj/Release/android/bin/classes.dex obj/Release/android/bin/classes /Library/Frameworks/Xamarin.Android.framework/Versions/Current/lib/mandroid/platforms/android-8/mono.android.jar obj/Release/__library_projects__/android-support-v4.jar

 - Jon

_______________________________________________
Monodroid mailing list
[hidden email]

UNSUBSCRIBE INFORMATION:
http://lists.ximian.com/mailman/listinfo/monodroid
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Building a package with a jar bindings library strips the jar file from the assembly

Vladimir Dimitrov
So after looking at the classes.dex it turns out that this library types
are not in there. Having in mind that this mean that "that's a problem.
:-)" what should be done to fix this problem?

On 26.11.2013 г. 16:14 ч., Jonathan Pryor wrote:

> On Nov 26, 2013, at 8:27 AM, Vladimir Dimitrov <[hidden email]> wrote:
>> I am trying to make a jar bindings project that I need in my app.
>> 1. I created a jar binding project.
>> 2. Added the .jar file in the Jars folder.
>> 3. Made it an EmbeddedJar
>> 4. Build the project
>> 5. Referenced the project from another project and added some logic using the callable wrappers.
>>
>> Now when I build the project I see that an assembly is generated with the .jar file inside it as a resource.
>> But when I try to run in debug mode I get a java.lang.NoClassDefFoundError exception.
>> I noticed that if I build an .apk, unzip it and decompile the jar bindings assembly, the jar file is no longer in it.
> This is by design, and is unrelated to your error.
>
> Android doesn't run Java bytecode, it runs Dalvik bytecode. Consequently, .jar files on device are entirely useless, and would only serve to bloat your application size for no benefit.
>
> Instead, what should be happening is that the .jar resource is extracted, and the .jar is then passed to dx.jar (the Dex compiler) along with all the other Java bytecode that makes up the app (compiled Android Callable Wrappers, etc.).
>
> The important part, then, is the `classes.dex` entry within the .apk. The "sanity check" is to extract your .apk, run `dexdump classes.dex`, and see if the type you're getting a NoClassDefFoundError for is present (or not present) within classes.dex. (`dexdump` is located in the Android SDK, e.g. $ANDROID_SDK_PATH/build-tools/19.0.0/dexdump.)
>
> Note that dexdump lists types in JNI format, e.g. you'll see "L/your/package/name/TypeName;".
>
> If the type is missing from classes.dex, that's a problem. :-)
>
> I would suggest cleaning everything, nuking all bin & obj directories, and rebuilding. If that doesn't fix it, please provide the diagnostic build output. In particular, you want to find `dx.jar` invocation, and double-check that your embedded .jar is listed:
>
> Tool /usr/bin/java execution started with arguments: -jar /opt/android/sdk/platform-tools/lib/dx.jar --no-strict --dex --output=obj/Release/android/bin/classes.dex obj/Release/android/bin/classes /Library/Frameworks/Xamarin.Android.framework/Versions/Current/lib/mandroid/platforms/android-8/mono.android.jar obj/Release/__library_projects__/android-support-v4.jar
>
>   - Jon
>
> _______________________________________________
> Monodroid mailing list
> [hidden email]
>
> UNSUBSCRIBE INFORMATION:
> http://lists.ximian.com/mailman/listinfo/monodroid

_______________________________________________
Monodroid mailing list
[hidden email]

UNSUBSCRIBE INFORMATION:
http://lists.ximian.com/mailman/listinfo/monodroid
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Building a package with a jar bindings library strips the jar file from the assembly

Jonathan Pryor-3
On Nov 28, 2013, at 11:29 AM, Vladimir Dimitrov <[hidden email]> wrote:
> So after looking at the classes.dex it turns out that this library types are not in there. Having in mind that this mean that "that's a problem. :-)" what should be done to fix this problem?

1. Determine which .jar those types come from.
2. Ensure that "somehow" that .jar is included within your app.

(2) has a variety of solutions. You could use AndroidJavaLibrary within the Application project, EmbeddedJar or EmbeddedReferenceJar within a Binding project, or <uses-library/> if it's a "platform-provided" type (this is the case for Google Maps v1, and certain Amazon libraries IIRC, meaning those types will _never_ appear within classes.dex, and that's OK.)

 - Jon

_______________________________________________
Monodroid mailing list
[hidden email]

UNSUBSCRIBE INFORMATION:
http://lists.ximian.com/mailman/listinfo/monodroid
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Building a package with a jar bindings library strips the jar file from the assembly

Vladimir Dimitrov
The types I need are in the posindev.jar I included in the jar bindings
project. It is marked as EmbededJar but the types from it are not in the
classes.dex and it causes the runtime error I am talking about. I have
sent you the whole library project so you can see if I am doing
something wrong, but the project is pretty empty with only the jar file
inside so I don't see what I can do wrong here.

- Vladimir

On 1.12.2013 г. 23:49 ч., Jonathan Pryor wrote:

> On Nov 28, 2013, at 11:29 AM, Vladimir Dimitrov <[hidden email]> wrote:
>> So after looking at the classes.dex it turns out that this library types are not in there. Having in mind that this mean that "that's a problem. :-)" what should be done to fix this problem?
> 1. Determine which .jar those types come from.
> 2. Ensure that "somehow" that .jar is included within your app.
>
> (2) has a variety of solutions. You could use AndroidJavaLibrary within the Application project, EmbeddedJar or EmbeddedReferenceJar within a Binding project, or <uses-library/> if it's a "platform-provided" type (this is the case for Google Maps v1, and certain Amazon libraries IIRC, meaning those types will _never_ appear within classes.dex, and that's OK.)
>
>   - Jon
>
> _______________________________________________
> Monodroid mailing list
> [hidden email]
>
> UNSUBSCRIBE INFORMATION:
> http://lists.ximian.com/mailman/listinfo/monodroid

_______________________________________________
Monodroid mailing list
[hidden email]

UNSUBSCRIBE INFORMATION:
http://lists.ximian.com/mailman/listinfo/monodroid
Loading...