I am trying to set up gdx-pay in my game. I have followed the official readme (https://github.com/libgdx/gdx-pay/), but can't seem to instantiate the PurchaseManager in my AndroidLauncher.
I have set up a class that handles PurchaseManager installation, but every time I try to instantiate it in the AndroidLauncher I get this error:
"java.lang.RuntimeException: Unable to start activity ComponentInfo{appPackage.AndroidLauncher}: java.lang.IllegalArgumentException: Support for pending purchases must be enabled. Enable this by calling 'enablePendingPurchases()' on BillingClientBuilder."
The readme says to add this to the AndroidLauncher onCreate
game.purchaseManager = new PurchaseManagerGoogleBilling(this);
The problem is that I have to add this
ProjectName.purchaseManager = new PurchaseManagerGoogleBilling(this);
This give me an error saying that I have to make purchaseManager static in my ProjectName class
When I do this, I get the RuntimeException mentioned above.
The sample gdx-pay project instantiates PurchaseManager with this code
public class AndroidLauncher extends GenericAndroidLauncher {
#Override
protected void initFlavor(GdxPayApp game) {
super.initFlavor(game);
game.purchaseManager = new PurchaseManagerGoogleBilling(this);
}
}
When I try this, #Override is invalid and initFlavor does not exist. I tried looking for initFlavor in the gdx-pay files, but had no luck finding anything...
Thanks for taking the time to help
Well it turns out that the following line in my android gradle was the issue
implementation 'com.android.billingclient:billing:2.0.1'
Gdx-pay takes care of this automatically and uses client 1.1
Setting the billingclient to 2.0.1 was the problem. I was able to fix it by deleting that line. Big thanks to the libGdx discord guys!
Related
All Code: https://gist.github.com/anonymous/e11f533921aa4308e29d
I have been following Bucky's "Learn Android Dev". I wrote this code out originally myself, but when it crashed on startup I then copied Bucky's source code. I am using a tablet to run this app, but it crashes on both VM's and the tablet itself with the error
Unfortunately, <app name> has stopped
Any ideas?
To use the GestureDetectorCompat class , you need to create an instance of the GestureDetectorCompat for your View. Refer this documentation.
So the code will fail with null pointer and so you will get ANR at this.gestureDetector.onTouchEvent(event);
So in your onCreate method add following code, should solve your issue.
gestureDetector=new GestureDetectorCompat(this,this);
gestureDetector.setOnDoubleTapListener(this);
I just started working on Google Tag Manager. I got it worked. But I faced one issue. That is, each time I edit or add some new macros, I need to create new version and publish it. Unless I am not downloading the new version and saving inside assets/tagmanager and also unless I refer with the new version name of the downloaded file, I am not able to see my updates.
Is it so? If so, I didn't understand why this is useful. Is anything done by me went wrong?
I got it worked.The issue was when we keep the json or binary inside assets folder, then on openContainer() call, Google Tag Manager will check for the saved file first. Then only it will goto the network and search. This caused issue to me. So I removed the file kept inside assets/tagmanager folder.
Also I called container.refresh() before we set value inside the singleton class.
Sample code:
ContainerOpener.openContainer(tagManager, CONTAINER_ID, OpenType.PREFER_NON_DEFAULT,
TIMEOUT_FOR_CONTAINER_OPEN_MILLISECONDS, new ContainerOpener.Notifier() {
#Override
public void containerAvailable(Container container) {
container.refresh();
// Save container for use by any other activities in the app.
WPContainerHolder.setContainer(container);
//perform your other functionalities
}
});
I am having trouble importing the zbar library properly.
I am following this guide:
https://github.com/DushyanthMaguluru/ZBarScanner
The guide says:
Download this project and add it as a library project to your existing Android app
I downloaded this project and created a library from ZbarScannerLibary folder. I then set in the properties of my project this liabry to be used.
I then continued the guide, when I started to code the main activity I received errors that variables and imports cannot be resolved.
What am I doing wrong and how can I get the imports to be resolved ?
just create a variable in your Activity:
public static final int ZBAR_SCANNER_REQUEST = 0;
public static final int ZBAR_OR_SCANNER_REQUEST = 1;
//etc
These are just used for handling activity result. In the short run, you can also comment out the onActivityResult method to test the barcode is working. You then open the barcode with:
startActivity(intent);
Finally, be sure to read up on startActivityForResult, since it is a very important topic when developing a multi-activity app.
I am trying to launch a new intent from my Activity, but I get a NoClassDefFoundError. The exception occurs resolving MyClassB.class. Oddly I can resolve other classes, and the error only occurs in android versions 2.2 and 2.3, it works fine in 4.0+.
Both the class that causes the error and the other classes that resolve successfully are in the same package as the Activity where the code is executing. Basically, the below code gives the below error on 2.2/2.3, but works fine on 4.0+. I have also tried using the full package name like: com.me.MyClassB.class, but get the same error.
I realized this question is pretty vague, but am thoroughly confused and hoping that somebody might be able to help.
package com.me;
public class MyActivity extends Activity
{
protected onCreate(Bundle bundle)
{
super.onCreat(bundle);
Class a = MyClassA.class;
Class b = MyClassB.class;
}
}
01-17 10:37:36.473: E/AndroidRuntime(1976): java.lang.NoClassDefFoundError: com.me.MyClassB
I'm not sure if this is the problem but in your onCreate method you need to add super.onCreate(bundle) at the beginning e.g.
protected onCreate(Bundle bundle)
{
super.onCreate(bundle);
Class a = MyClassA.class;
Class b = MyClassB.class;
}
This was caused because MyClassB.class implements ActionBar.OnNavigationListener. It seems if classes contain certain code for a higher api level, they don't get setup properly at runtime, resulting in these sorts of errors. I expecteded MyClassB.class to crash on 2.3, but the NoClassDefFoundError was particularly mystifying.
In the onCreate() method of the activity I want the interstitial to appear in,
I have the following code:
MMAdView interAdView = new MMAdView(this, MY_APP_ID, MMAdView.FULLSCREEN_AD_LAUNCH, true, null);
interAdView.fetch();
interAdView.setListener(new BasicMMAdListener()
{
#Override
public void MMAdCachingCompleted(MMAdView adview, boolean success)
{
if(success)
adview.display();
}
});
The code compiles without error, but at runtime I get the following Log output
which indicates an error at the first line of my code snippet, i.e. the one
starting: MMAdView interAdView = new MMAdView(this, ...
Could not find class 'com.millennialmedia.android.MMAdView', referenced from method com.mycompany.mygame.myactivity.onCreate
I am puzzled because I thought that if there was somehow a missing
class then the app should not compile.
Thanks to Vinay's comment, it forced me to investigate another problem I'd been having first.
My problem disappeared when I resolve an earlier problem covered on SO here.