libgdx / gdx-pay

A libGDX cross-platform API for InApp purchasing.
Apache License 2.0
225 stars 83 forks source link

java.lang.NoClassDefFoundError #2

Closed just4phil closed 9 years ago

just4phil commented 9 years ago

@noblemaster i added the gdx-pay projects to my game and added them to the build-paths but i always get java.lang.NoClassDefFoundError: com.badlogic.gdx.pay.android.ouya.PurchaseManagerAndroidOUYA (and for the androidIAB too) what can be the reason? (does all that reflection code work properly?)

Tom-Ski commented 9 years ago

How exactly did you do this? Looks like you just don't have the dependent libs in your build path. Ouya-SDK and the open-iab jars.

noblemaster commented 9 years ago

You need to place the gdx-pay-android-openiab.jar and gdx-pay-android-ouya.jar into your project as well to get this to work. What exact error message are you getting?

just4phil commented 9 years ago

@Tom-Ski , @noblemaster i forked the gdx-pay-repo and cloned it to my local pc then i gradle-imported the projects into my actual game then i removed all my former integrated gdx-pay-stuff and added the new gdx-pay-projects to the build-path of the android-project and the core-project the OUYA-sdk.jar is in place..... but why do i need gdx-pay-android-openiab.jar and gdx-pay-android-ouya.jar when i have the sources? and where do i get them?

Tom-Ski commented 9 years ago

Because those projects depend on the ouya-sdk and openiab.jar.

Don't add to build path if you have imported via gradle, add it with Gradle, then it will link up dependencies correctly.

If you don't want to do that, you have to manually add the jars to your build path from the projects/lib folders. This is because these jars are hooked up with Gradle, by adding projects to the build path in the eclipse way, you are ignoring everything that Gradle has hooked up correctly in those projects.

just4phil commented 9 years ago

Sorry..... maybe I'm blind but where do I get those jars or must I rename ouya-sdk.jar and openIAB.jar???

Tom-Ski commented 9 years ago

You reference those jars.

noblemaster commented 9 years ago

why do i need gdx-pay-android-openiab.jar and gdx-pay-android-ouya.jar when i have the sources?

In that case you will need to add ouya-sdk.jar and openiab.jar only.

maybe I'm blind but where do I get those jars

gdx-pay-android-openiab.jar and gdx-pay-android-ouya.jar where built when gdx-pay was still within the libGDX project as an extension. Now that gdx-pay is in a separate repo, they will need to be built from sources. We should add a "dist" task to gradle. @MobiDevelop has promised to set it up but I guess he didn't have time to get to it yet. Also, it would be nice to have nightlies and release builds for those jars and upload them somewhere.

MobiDevelop commented 9 years ago

I don't really think there needs to be a zip distribution. If you guys do, feel free to create a "dist" task.

All the artifacts are being published to Sonatype.

noblemaster commented 9 years ago

I don't really think there needs to be a zip distribution. If you guys do, feel free to create a "dist" task.

I thought you were going to do that? I definitely agree that maven makes sense for use libgdx/gdx-pay/etc. developers. Thanks for setting that up! :) However for users/app developers using maven seems little bit overkill. Especially if you still have to add the ouya-sdk.jar etc. by hand anyway. There is a ZIP distribution for libgdx which I think is great. I actually added building of the gdx-pay-*.jars in there. Now that gdx-pay is in a separate repo, that won't work anymore. I guess I'll just have to do it again for gdx-pay unless someone else is coming forward...

MobiDevelop commented 9 years ago

Overkill? The majority of libgdx users are using Gradle already.

All they have to do is add the dependency to their build.gradle. If they target ouya there is the extra step of adding the jar they should have downloaded when they became an ouya developer. Then add a couple permissions to their manifest.

just4phil commented 9 years ago

@noblemaster, @Tom-Ski ok guys, i tried it again:

  1. fork
  2. clone to local pc
  3. importing into workspace of my game via gradle
  4. i added the core project (gdx-pay-gdx-pay) to the build-path of my games-core-project
  5. i added the core project (gdx-pay-gdx-pay) to the build-path of my games-android-project
  6. i added projects: android + android-openiab + android-ouya to the build-path of my games-android-project (inside is an OUYA-plaform-resolver and an android-platform-resolver)
  7. my ouya-resolver now calls "if (PurchaseSystem.hasManager()) { ......"

now i dont get any crashes anymore, BUT the purchaseManager is == null .... i debugged a bit and it seems that the reflection code doesnt work as expected (at least on ouya)

can someone tell me how exactly it should work and in what order? it seems confusing....

by the way: it works when i manually set the manager: PurchaseSystem.setManager(new PurchaseManagerAndroidOUYA(androidApplication, 0));

noblemaster commented 9 years ago

Are you using proguard when deploying to your device? Some classes, i.e. IAP.java might have been removed by proguard because proguard thought they weren't needed?

Anyhow, could you also post your log output?

just4phil commented 9 years ago

i dont use proguard.

here is the log:

10-13 21:02:08.533: I/(1289): Loaded EGL implementation /system/lib//egl/libEGL_tegra_impl 10-13 21:02:08.533: D/libEGL(1289): loaded /system/lib/egl/libGLESv1_CM_tegra.so 10-13 21:02:08.533: D/libEGL(1289): loaded /system/lib/egl/libGLESv2_tegra.so 10-13 21:02:08.563: E/dalvikvm(1289): Could not find class 'com.badlogic.gdx.pay.android.ouya.PurchaseManagerAndroidOUYA', referenced from method de.philweb.game2.android.OUYAResolver. 10-13 21:02:08.563: W/dalvikvm(1289): VFY: unable to resolve new-instance 968 (Lcom/badlogic/gdx/pay/android/ouya/PurchaseManagerAndroidOUYA;) in Lde/philweb/game2/android/OUYAResolver; 10-13 21:02:08.563: D/dalvikvm(1289): VFY: replacing opcode 0x22 at 0x000d 10-13 21:02:08.563: I/dalvikvm(1289): Could not find method com.badlogic.gdx.pay.PurchaseSystem.hasManager, referenced from method de.philweb.game2.android.OUYAResolver.requestPurchase 10-13 21:02:08.563: W/dalvikvm(1289): VFY: unable to resolve static method 8717: Lcom/badlogic/gdx/pay/PurchaseSystem;.hasManager ()Z 10-13 21:02:08.563: D/dalvikvm(1289): VFY: replacing opcode 0x71 at 0x0000 10-13 21:02:08.563: I/dalvikvm(1289): Could not find method com.badlogic.gdx.pay.PurchaseSystem.hasManager, referenced from method de.philweb.game2.android.OUYAResolver.requestPurchaseRestore 10-13 21:02:08.563: W/dalvikvm(1289): VFY: unable to resolve static method 8717: Lcom/badlogic/gdx/pay/PurchaseSystem;.hasManager ()Z 10-13 21:02:08.563: D/dalvikvm(1289): VFY: replacing opcode 0x71 at 0x0000 10-13 21:02:08.563: D/dalvikvm(1289): DexOpt: unable to opt direct call 0x2214 at 0x0f in Lde/philweb/game2/android/OUYAResolver;. 10-13 21:02:08.563: D/dalvikvm(1289): DexOpt: unable to opt direct call 0x2208 at 0x1d in Lde/philweb/game2/android/OUYAResolver;. 10-13 21:02:08.563: D/dalvikvm(1289): DexOpt: unable to opt direct call 0x2205 at 0x22 in Lde/philweb/game2/android/OUYAResolver;. 10-13 21:02:08.563: I/dalvikvm(1289): DexOpt: unable to optimize static field ref 0x11f3 at 0x25 in Lde/philweb/game2/android/OUYAResolver;. 10-13 21:02:08.563: I/dalvikvm(1289): Failed resolving Lde/philweb/game2/android/OUYAResolver$2; interface 964 'Lcom/badlogic/gdx/pay/PurchaseObserver;' 10-13 21:02:08.563: W/dalvikvm(1289): Link of class 'Lde/philweb/game2/android/OUYAResolver$2;' failed 10-13 21:02:08.563: D/dalvikvm(1289): DexOpt: unable to opt direct call 0x387b at 0x47 in Lde/philweb/game2/android/OUYAResolver;. 10-13 21:02:08.563: D/AndroidRuntime(1289): Shutting down VM 10-13 21:02:08.563: W/dalvikvm(1289): threadid=1: thread exiting with uncaught exception (group=0x40e8e300) 10-13 21:02:08.563: E/ACRA(1289): ACRA caught a NoClassDefFoundError exception for de.philweb.tanks. Building report. 10-13 21:02:08.573: D/ACRA(1289): Using default Report Fields 10-13 21:02:08.773: I/ACRA(1289): READ_LOGS granted! ACRA can include LogCat and DropBox data. 10-13 21:02:08.793: D/ACRA(1289): Retrieving logcat output... 10-13 21:02:08.813: D/ACRA(1289): Writing crash report file 1413234128000.stacktrace. 10-13 21:02:08.833: D/ACRA(1289): About to start ReportSenderWorker from #handleException 10-13 21:02:08.833: D/ACRA(1289): Mark all pending reports as approved. 10-13 21:02:08.833: D/ACRA(1289): Looking for error files in /data/data/de.philweb.tanks/files 10-13 21:02:08.833: D/ACRA(1289): #checkAndSendReports - start 10-13 21:02:08.833: D/ACRA(1289): Looking for error files in /data/data/de.philweb.tanks/files 10-13 21:02:08.833: I/ACRA(1289): Sending file 1413234128000-approved.stacktrace 10-13 21:02:08.833: D/ACRA(1289): Waiting for Toast + worker... 10-13 21:02:08.863: D/ACRA(1289): Connect to http://www...... 10-13 21:02:08.913: D/ACRA(1289): Sending request to acra 10-13 21:02:11.103: W/ResponseProcessCookies(1289): Invalid cookie header: "Set-Cookie: bugsense.locale=en_US; expires=Wed, 12-Nov-2014 21:02:11 GMT; Max-Age=2592000; Path=/". Unable to parse expires attribute: Wed 10-13 21:02:11.113: D/ACRA(1289): #checkAndSendReports - finish 10-13 21:02:11.133: D/ACRA(1289): Wait for Toast + worker ended. Kill Application ? true 10-13 21:02:11.143: E/AndroidRuntime(1289): FATAL EXCEPTION: main 10-13 21:02:11.143: E/AndroidRuntime(1289): java.lang.NoClassDefFoundError: com.badlogic.gdx.pay.android.ouya.PurchaseManagerAndroidOUYA 10-13 21:02:11.143: E/AndroidRuntime(1289): at de.philweb.game2.android.OUYAResolver.(OUYAResolver.java:40) 10-13 21:02:11.143: E/AndroidRuntime(1289): at de.philweb.game2.android.AndroidLauncher.onCreate(AndroidLauncher.java:29) 10-13 21:02:11.143: E/AndroidRuntime(1289): at android.app.Activity.performCreate(Activity.java:5063) 10-13 21:02:11.143: E/AndroidRuntime(1289): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1079) 10-13 21:02:11.143: E/AndroidRuntime(1289): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2023) 10-13 21:02:11.143: E/AndroidRuntime(1289): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2084) 10-13 21:02:11.143: E/AndroidRuntime(1289): at android.app.ActivityThread.access$600(ActivityThread.java:130) 10-13 21:02:11.143: E/AndroidRuntime(1289): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1195) 10-13 21:02:11.143: E/AndroidRuntime(1289): at android.os.Handler.dispatchMessage(Handler.java:99) 10-13 21:02:11.143: E/AndroidRuntime(1289): at android.os.Looper.loop(Looper.java:137) 10-13 21:02:11.143: E/AndroidRuntime(1289): at android.app.ActivityThread.main(ActivityThread.java:4745) 10-13 21:02:11.143: E/AndroidRuntime(1289): at java.lang.reflect.Method.invokeNative(Native Method) 10-13 21:02:11.143: E/AndroidRuntime(1289): at java.lang.reflect.Method.invoke(Method.java:511) 10-13 21:02:11.143: E/AndroidRuntime(1289): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786) 10-13 21:02:11.143: E/AndroidRuntime(1289): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553) 10-13 21:02:11.143: E/AndroidRuntime(1289): at dalvik.system.NativeStart.main(Native Method) 10-13 21:02:11.143: W/ActivityManager(326): Force finishing activity de.philweb.tanks/de.philweb.game2.android.AndroidLauncher 10-13 21:02:11.183: W/ActivityManager(326): Force finishing activity tv.ouya.console/.launcher.developer.MakeActivity

just4phil commented 9 years ago

right now i have a second problem: i always get: "Conversion to Dalvik format failed with error 1" i dont see any reason for this.... i already tried different solutions (new repo, restart eclipse, clean/build, ..) but nothing helped.... when i delete "private libraries" in eclipse build path it works.... but is that a good idea??? has anyone any suggestion?

here is the error message ....

[2014-10-13 23:16:31 - game2-android] Dx trouble processing "java/util/EventListenerProxy.class":

Ill-advised or mistaken usage of a core class (java.* or javax.*) when not building a core library.

This is often due to inadvertently including a core library file in your application's project, when using an IDE (such as Eclipse). If you are sure you're not intentionally defining a core class, then this is the most likely explanation of what's going on.

[...]

[2014-10-13 23:16:31 - game2-android] Dx 1 error; aborting [2014-10-13 23:16:31 - game2-android] Conversion to Dalvik format failed with error 1

noblemaster commented 9 years ago

Thanks for the log output!

Could not find method com.badlogic.gdx.pay.PurchaseSystem.hasManager, referenced from method de.philweb.game2.android.OUYAResolver.requestPurchase

That seems pretty odd given you included it. I wonder: did you include all the gdx-pay projects as Android libraries as well? I think just adding them to your build path only might not work for Android? In any case, go into project settings and under "Android" (above the "Java Build Path") add all the projects as libraries. Does that work?

noblemaster commented 9 years ago

The majority of libgdx users are using Gradle already.

Not sure where you got your numbers from? Seems that all the people that posted would prefer jars which seems odd given that the "majority" is using Gradle. The big libgdx-motherproject doesn't contain Gradle either. And providing a bunch of task-less gradle files for each of the projects doesn't help getting your point over either. At least a dist task as it is provided in libgdx setup would have been nice :)

MobiDevelop commented 9 years ago

I'm talking about libgdx users. People using libgdx as a library, not people working on libgdx itself.

The gradle files build and publish the artifacts. They have the tasks needed to accomplish that goal. Users are not supposed to download and use these projects... the average user will add the dependency to their project, add a couple manifest entries and be on with their business.

just4phil commented 9 years ago

@noblemaster i tried adding the projects as libraries ("add class folders").... but then eclipse says: Build path contains duplicate entry:...openiab' for project 'game2-android' when i remove the projects from the projects tab... then the classes cant be resolved anymore.... it sucks .....

noblemaster commented 9 years ago

That's the wrong place. I assume you are using Eclipse? On the very left side of the properties window for your project there is the "Java Build Path" that you have selected. Instead, select "Android" a few list items above "Java Build Path". In there, on the bottom of the right hand side there is a checkbox called "Is Android Library". Don't select that, but underneath, add the gdx-pay projects using the "Add..." button! You might have to make those gdx-pay projects library projects first before you can add them? I wonder? I haven't setup the gdx-pay repo so I am not sure if that was done?

MobiDevelop commented 9 years ago

The are not set up as Android library projects. They don't need to be.

MobiDevelop commented 9 years ago

Here's what I did to use the gdx-pay repo via Gradle, with normal Eclipse projects (this is not really a recommended approach, but it works fine).

just4phil commented 9 years ago

THX! Will try that this evening.... Am 15.10.2014 06:54 schrieb "Justin Shapcott" notifications@github.com:

Here's what I did to use the gdx-pay repo via Gradle, with normal Eclipse projects (this is not really a recommended approach, but it works fine).

  • Gradle import the gdx-pay projects into your workspace.
  • Add a reference to the main gdx-pay project to your core project.
  • Add a reference to the gdx-pay-android (plus openiab and/or ouya variants) to your android project.
  • Add a reference to the openiab jar (get the path from the openiab project Gradle Dependencies) to your android project
  • Add a reference to the ouya jar (from ouya project lib directory) to your android project
  • Add whatever permissions you need for the stores you are targeting to your AndroidManifest.xml

— Reply to this email directly or view it on GitHub https://github.com/libgdx/gdx-pay/issues/2#issuecomment-59157622.

just4phil commented 9 years ago

@MobiDevelop ....Add a reference to the main gdx-pay project to your core project.....

sigh* when i go in eclipse to build path -> source -> link source and add the reference to the gdx-pay project then i get the eclipse error: The declared package "com.badlogic.gdx.pay" does not match the expected package "src.com.badlogic.gdx.pay"

the same happens with all references in all projects ....

MobiDevelop commented 9 years ago

Don't do linked source, add a project reference.

just4phil commented 9 years ago

ok.... now i have no errors.... but still running on my ouya doesnt work:

10-15 18:52:50.424: E/AndroidRuntime(1513): FATAL EXCEPTION: main 10-15 18:52:50.424: E/AndroidRuntime(1513): java.lang.NoClassDefFoundError: com.badlogic.gdx.pay.android.ouya.PurchaseManagerAndroidOUYA 10-15 18:52:50.424: E/AndroidRuntime(1513): at de.philweb.game2.android.OUYAResolver.(OUYAResolver.java:40) 10-15 18:52:50.424: E/AndroidRuntime(1513): at de.philweb.game2.android.AndroidLauncher.onCreate(AndroidLauncher.java:29) 10-15 18:52:50.424: E/AndroidRuntime(1513): at android.app.Activity.performCreate(Activity.java:5063) 10-15 18:52:50.424: E/AndroidRuntime(1513): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1079) 10-15 18:52:50.424: E/AndroidRuntime(1513): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2023) 10-15 18:52:50.424: E/AndroidRuntime(1513): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2084) 10-15 18:52:50.424: E/AndroidRuntime(1513): at android.app.ActivityThread.access$600(ActivityThread.java:130) 10-15 18:52:50.424: E/AndroidRuntime(1513): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1195) 10-15 18:52:50.424: E/AndroidRuntime(1513): at android.os.Handler.dispatchMessage(Handler.java:99) 10-15 18:52:50.424: E/AndroidRuntime(1513): at android.os.Looper.loop(Looper.java:137) 10-15 18:52:50.424: E/AndroidRuntime(1513): at android.app.ActivityThread.main(ActivityThread.java:4745) 10-15 18:52:50.424: E/AndroidRuntime(1513): at java.lang.reflect.Method.invokeNative(Native Method) 10-15 18:52:50.424: E/AndroidRuntime(1513): at java.lang.reflect.Method.invoke(Method.java:511) 10-15 18:52:50.424: E/AndroidRuntime(1513): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786) 10-15 18:52:50.424: E/AndroidRuntime(1513): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553) 10-15 18:52:50.424: E/AndroidRuntime(1513): at dalvik.system.NativeStart.main(Native Method)

MobiDevelop commented 9 years ago

Are you exporting everything you need? Check your Order and Export tab in Build Path settings of your android project.

just4phil commented 9 years ago

yeah .... it works a bit..... at least the game starts :) BUT.... still not purchaseManagerOUYA available! (== null) so....after all this mess.... i guess that the reflection part for the ouya-purchasemanager maybe doesnt work?

MobiDevelop commented 9 years ago

I just tried on my Ouya... It worked for me after I fixed a bug in PurchaseManagerAndroidOUYA.

This bug was not related to the reflection, however.

just4phil commented 9 years ago

OK...what was the Problem? Did you commit the fix? Am 16.10.2014 06:33 schrieb "Justin Shapcott" notifications@github.com:

I just tried on my Ouya... It worked for me after I fixed a bug in PurchaseManagerAndroidOUYA.

— Reply to this email directly or view it on GitHub https://github.com/libgdx/gdx-pay/issues/2#issuecomment-59312959.

MobiDevelop commented 9 years ago

No, I haven't committed the fix yet. The problem is you are creating a handler on the GL Thread, which hasn't called Looper.prepare().

just4phil commented 9 years ago

Ok....i can check that this evening.... THX!

MobiDevelop commented 9 years ago

There is another problem though, the Ouya purchase manager only works once - if you exit and come back without the process being killed, it cannot create the purchase manager the second time.

just4phil commented 9 years ago

@MobiDevelop Hmmm but even when there is no looper the manager object should not be null....?!

MobiDevelop commented 9 years ago

No clue how you got a null purchase manager.

By the way, the "only works once" problem is not exclusive to the Ouya purchase manager. The same behavior exists for the OpenIAB version too.

noblemaster commented 9 years ago

To exit properly, PurchaseSystem.dispose() has to be called. It's in the test.

By the way, shouldn't the gdx-pay-tests-android project be setup as an Android project? It's not actually a Desktop project.

MobiDevelop commented 9 years ago

Yes, it is the dispose call that makes it not work the second time around.

Yes, gdx-pay-tests-android is set up as an Android project.

noblemaster commented 9 years ago

Yes, gdx-pay-tests-android is set up as an Android project.

Not for Eclipse after I import Gradle. It is setup as a Desktop project.

MobiDevelop commented 9 years ago

Then you imported wrong. It is an Android project for me.

MobiDevelop commented 9 years ago

Sorry, you are right, I missed some things in my initial commit that I had done on my end for Eclipse.

noblemaster commented 9 years ago

That worked great - Thanks :)

just4phil commented 9 years ago

What must i do to fix the project settings? Bye Phil Am 16.10.2014 15:59 schrieb "Christoph Aschwanden" < notifications@github.com>:

That worked great - Thanks :)

— Reply to this email directly or view it on GitHub https://github.com/libgdx/gdx-pay/issues/2#issuecomment-59365033.

noblemaster commented 9 years ago

Actually I just run the Android tests and it didn't work. Although it's an Android project now, the dependencies for the jars etc. are not set correctly...

MobiDevelop commented 9 years ago

Hmm, works for me.

I don't really have time to help you guys figure out how to export things on your projects I'm afraid.

noblemaster commented 9 years ago

OK, I fixed the gradle build file. @just4phil: you should be able to run the Android application now. You might want to refresh your gradle setup etc.

Also, I fixed the problem where no payment manager was instantiated the second time around (reflection). Using a static { } initializer meant, the purchase manager was only resolved the first time the app was run but not the second time around.

just4phil commented 9 years ago

@noblemaster ... i have no idea what is going wrong here...... i tried all the stuff again....but it still doesnt work.... my OUYApurchaseManager is always == null. it only works when i manually add the manager like this: PurchaseSystem.setManager(new PurchaseManagerAndroidOUYA(androidApplication, 0));

here is what i did:

github.com: fork https://github.com/libgdx/gdx-pay.git local pc: sourcetree: clone fork to local pc eclipse: import gradle project eclipse: build path -> add project references:

Check Order and Export tab in Build Path settings of android project: Are you exporting everything you need? => ok!

noblemaster commented 9 years ago

Does Google Play work? Try the following:

  1. do a fresh checkout of gdx-pay
  2. run the gradle wrapper
  3. import the gradle files into Eclipse
  4. run gdx-pay-tests-android as Android Application

Does Google Play work (i.e. non-null)?

just4phil commented 9 years ago

OK but what is the gradle wrapper? Am 19.10.2014 17:59 schrieb "Christoph Aschwanden" <notifications@github.com

:

Does Google Play work? Try the following:

  1. do a fresh checkout of gdx-pay
  2. run the gradle wrapper
  3. import the gradle files into Eclipse
  4. run gdx-pay-tests-android as Android Application

Does Google Play work (i.e. non-null)?

— Reply to this email directly or view it on GitHub https://github.com/libgdx/gdx-pay/issues/2#issuecomment-59654284.

noblemaster commented 9 years ago

double-click gradlew in the root of the repository.

just4phil commented 9 years ago

ok android-test runs on my phone and works! but on OUYA still no manager (==null)

noblemaster commented 9 years ago

Same error message as before? Would you mind posting it again so I can check where it fails (sorry)!