1

This is my class:

import com.google.android.vending.licensing.AESObfuscator;
import com.google.android.vending.licensing.LicenseCheckerCallback;
import com.google.android.vending.licensing.LicenseChecker;
import com.google.android.vending.licensing.ServerManagedPolicy;

import android.app.Activity;
import android.app.AlertDialog;
import android.app.Dialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.provider.Settings.Secure;
import android.widget.Toast;

public class LicenseCheck extends Activity {
    private class MyLicenseCheckerCallback implements LicenseCheckerCallback {
        @Override
        public void allow(int reason) {
            if (isFinishing()) {
                // Don't update UI if Activity is finishing.
                return;
            }
            // Should allow user access.
            startMainActivity(true);
        }

        @Override
        public void applicationError(int errorCode) {
            if (isFinishing()) {
                // Don't update UI if Activity is finishing.
                return;
            }
            // This is a polite way of saying the developer made a mistake
            // while setting up or calling the license checker library.
            // Please examine the error code and fix the error.
            toast("Error Code: " + errorCode);
            startMainActivity(false);

        }

        @Override
        public void dontAllow(int reason) {
            if (isFinishing()) {
                // Don't update UI if Activity is finishing.
                return;
            }

            // Should not allow access. In most cases, the app should assume
            // the user has access unless it encounters this. If it does,
            // the app should inform the user of their unlicensed ways
            // and then either shut down the app or limit the user to a
            // restricted set of features.
            // In this example, we show a dialog that takes the user to Market.
            showDialog(0);
            startMainActivity(false);
        }
    }

    private static final String BASE64_PUBLIC_KEY = "PLACE YOUR BASE KEY FROM GOOGLE HERE";

    private static final byte[] SALT = new byte[] { 13, 32, 81, 65, 53, 82, 18, 100, -69, -17, 51, 79, -15, 86, -10, -40, 19, 45, 63, -7 };
    private LicenseChecker mChecker;

    // A handler on the UI thread.

    private LicenseCheckerCallback mLicenseCheckerCallback;

    private void doCheck() {

        mChecker.checkAccess(mLicenseCheckerCallback);
    }

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        // Try to use more data here. ANDROID_ID is a single point of attack.
        String deviceId = Secure.getString(getContentResolver(), Secure.ANDROID_ID);

        // Library calls this when it's done.
        mLicenseCheckerCallback = new LicenseCheck.MyLicenseCheckerCallback();
        // Construct the LicenseChecker with a policy.
        mChecker = new LicenseChecker(this, new ServerManagedPolicy(this, new AESObfuscator(SALT, getPackageName(), deviceId)), BASE64_PUBLIC_KEY);
        doCheck();

    }

    @Override
    protected Dialog onCreateDialog(int id) {
        // We have only one dialog.
        return new AlertDialog.Builder(this).setTitle("Application Not Licensed").setCancelable(false).setMessage("This application is not licensed. In order to use this feature Please purchase it from Android Market")
                .setPositiveButton("Buy App", new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        Intent marketIntent = new Intent(Intent.ACTION_VIEW, Uri.parse("http://market.android.com/details?id=" + getPackageName()));
                        startActivity(marketIntent);
                        finish();
                    }
                }).setNegativeButton("Exit", new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        finish();
                    }
                }).create();
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        mChecker.onDestroy();
    }

    private void startMainActivity(boolean isLicensed) {
        Intent intent = new Intent(this, MainActivity.class);
        Bundle b = new Bundle();
        b.putBoolean(CommunicationStrings.isLicensed, isLicensed);
        intent.putExtras(b); //Put your id to your next Intent
        startActivity(intent); // REPLACE MainActivity.class WITH YOUR APPS ORIGINAL LAUNCH ACTIVITY
        finish();
    }

    public void toast(String string) {
        Toast.makeText(this, string, Toast.LENGTH_SHORT).show();
    }
}

This is the logcat:

07-06 10:41:02.765: E/AndroidRuntime(24277): FATAL EXCEPTION: main
07-06 10:41:02.765: E/AndroidRuntime(24277): java.lang.NoClassDefFoundError: com.XX.XXXXXXX.LicenseCheck$MyLicenseCheckerCallback
07-06 10:41:02.765: E/AndroidRuntime(24277):    at com.ck.autoWiFi3G.LicenseCheck.onCreate(LicenseCheck.java:85)
07-06 10:41:02.765: E/AndroidRuntime(24277):    at android.app.Activity.performCreate(Activity.java:5206)
07-06 10:41:02.765: E/AndroidRuntime(24277):    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1083)
07-06 10:41:02.765: E/AndroidRuntime(24277):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2064)
07-06 10:41:02.765: E/AndroidRuntime(24277):    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2125)
07-06 10:41:02.765: E/AndroidRuntime(24277):    at android.app.ActivityThread.access$600(ActivityThread.java:140)
07-06 10:41:02.765: E/AndroidRuntime(24277):    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1227)
07-06 10:41:02.765: E/AndroidRuntime(24277):    at android.os.Handler.dispatchMessage(Handler.java:99)
07-06 10:41:02.765: E/AndroidRuntime(24277):    at android.os.Looper.loop(Looper.java:137)
07-06 10:41:02.765: E/AndroidRuntime(24277):    at android.app.ActivityThread.main(ActivityThread.java:4898)
07-06 10:41:02.765: E/AndroidRuntime(24277):    at java.lang.reflect.Method.invokeNative(Native Method)
07-06 10:41:02.765: E/AndroidRuntime(24277):    at java.lang.reflect.Method.invoke(Method.java:511)
07-06 10:41:02.765: E/AndroidRuntime(24277):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1006)
07-06 10:41:02.765: E/AndroidRuntime(24277):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:773)
07-06 10:41:02.765: E/AndroidRuntime(24277):    at dalvik.system.NativeStart.main(Native Method)

I found this post that talk about this error: noclassdeferror for inner class MyLicenseCheckerCallback

But it didn't help me. I tried clean project, add google play license as a jar (in build path) file. Nothing helped...

What could be the problem?

Community
  • 1
  • 1
Alex K
  • 5,092
  • 15
  • 50
  • 77

2 Answers2

0

may you can try this.. Right click on Project-->build Path-->Configure Build Path-->java build path-->order and export tab-->check tick mark on your jar-->click ok

now clean project

ʌɐɥqıɐʌ
  • 137
  • 16
0

I had the exact same exception and none of the above recommendations worked for me.

However I got mine working by ensuring that your LVL project is a library project (right click project -> properties -> android and tick the "Is Libary" checkbo).

To include this in your application project remove any other references to this and apply the changes. Then if not already there navigate to (right click application project --> properties --> android) and in the library section click Add and select your LVL project. Apply Changes. Ok and clean project.

Hope this helps someone.