0

Im trying to do this tutorial But keep getting this error:

08-21 14:12:49.599: E/AndroidRuntime(714): java.lang.NoClassDefFoundError: com.akiraapps.LicenseCheck$MyLicenseCheckerCallback

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.os.Handler;
import android.provider.Settings.Secure;
import android.view.View;
import android.view.Window;
import android.widget.Button;
import android.widget.TextView;

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


public class LicenseCheck extends Activity {

    private static final String BASE64_PUBLIC_KEY = "no";

    private static final byte[] SALT = new byte[] { no};

    private TextView mStatusText;
    private Button mCheckLicenseButton;

    private LicenseCheckerCallback mLicenseCheckerCallback;
    private LicenseChecker mChecker;
    // A handler on the UI thread.
    private Handler mHandler;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        requestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS);
        setContentView(R.layout.main);

        mStatusText = (TextView) findViewById(R.id.status_text);
        mCheckLicenseButton = (Button) findViewById(R.id.check_license_button);
        mCheckLicenseButton.setOnClickListener(new View.OnClickListener() {
            public void onClick(View view) {
                doCheck();
            }
        });

        mHandler = new Handler();

        // 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 MyLicenseCheckerCallback();
        // Construct the LicenseChecker with a policy.
        mChecker = new LicenseChecker(
            this, new ServerManagedPolicy(this,
                new AESObfuscator(SALT, getPackageName(), deviceId)),
            BASE64_PUBLIC_KEY);
        doCheck();
    }

    protected Dialog onCreateDialog(int id) {
        final boolean bRetry = id == 1;
        return new AlertDialog.Builder(this)
            .setTitle(R.string.unlicensed_dialog_title)
            .setMessage(bRetry ? R.string.unlicensed_dialog_retry_body : R.string.unlicensed_dialog_body)
            .setPositiveButton(bRetry ? R.string.retry_button : R.string.buy_button, new DialogInterface.OnClickListener() {
                boolean mRetry = bRetry;
                public void onClick(DialogInterface dialog, int which) {
                    if ( mRetry ) {
                        doCheck();
                    } else {
                        Intent marketIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(
                                "http://market.android.com/details?id=" + getPackageName()));
                            startActivity(marketIntent);                        
                    }
                }
            })
            .setNegativeButton(R.string.quit_button, new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int which) {
                    finish();
                }
            }).create();
    }

    private void doCheck() {
        mCheckLicenseButton.setEnabled(false);
        setProgressBarIndeterminateVisibility(true);
        mStatusText.setText(R.string.checking_license);
        mChecker.checkAccess(mLicenseCheckerCallback);
    }

    private void displayResult(final String result) {
        mHandler.post(new Runnable() {
            public void run() {
                mStatusText.setText(result);
                setProgressBarIndeterminateVisibility(false);
                mCheckLicenseButton.setEnabled(true);
            }
        });
    }

    private void displayDialog(final boolean showRetry) {
        mHandler.post(new Runnable() {
            public void run() {
                setProgressBarIndeterminateVisibility(false);
                showDialog(showRetry ? 1 : 0);
                mCheckLicenseButton.setEnabled(true);
            }
        });
    }    

    private class MyLicenseCheckerCallback implements LicenseCheckerCallback {
        public void allow(int policyReason) {
            System.out.println("Allow");
            if (isFinishing()) {
                // Don't update UI if Activity is finishing.
                return;
            }
            // Should allow user access.
            displayResult(getString(R.string.allow));
        }

        public void dontAllow(int policyReason) {
            System.out.println("dontAllow");
            if (isFinishing()) {
                // Don't update UI if Activity is finishing.
                return;
            }
            displayResult(getString(R.string.dont_allow));
            // 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.
            // If the reason for the lack of license is that the service is
            // unavailable or there is another problem, we display a
            // retry button on the dialog and a different message.
            displayDialog(policyReason == Policy.RETRY);
        }

        public void applicationError(int errorCode) {
            System.out.println("applicationError");
            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.
            String result = String.format(getString(R.string.application_error), errorCode);
            displayResult(result);
        }
    }

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

}

I follow the tutorial for setting up LVL as a library project and those imports seem to be ok.

Why do I get this error? Why can it not find the inner class? If I right click and say show definition it jumps to the inner class.

rene
  • 37,946
  • 78
  • 99
  • 132
owen gerig
  • 6,026
  • 6
  • 48
  • 85
  • this topic is the same but no answer :( http://stackoverflow.com/questions/9740514/license-checker-crashes-after-rev-update – owen gerig Aug 21 '12 at 19:32
  • copied sample from the sample directory and still same error (updated code above to reflect that)? – owen gerig Aug 21 '12 at 20:46
  • used only the sample from android and still got the error. this is an eclipse setting (something with the class path all the same though) in my opinion. – owen gerig Aug 22 '12 at 00:55

3 Answers3

2

I had same problem.

Below steps solved the probelm

  1. take standard library example
  2. coppied the library.jar file from the library project into your libs folder
Rakesh Patil
  • 190
  • 2
  • 11
1

So this SO Answer is what fixed it I created a folder called libs and coppied the library.jar file from the library project included in the licensing package downloaded with the manager

What I dont understand is per this answer this should have been done for me As I am using ADT 20.0.3

Basically it comes down to an example that I downloaded directly from android and got stuck for a few hours trying to figure out what was wrong and this seems like this step should have been in the readme/help docs OR Im doing something wrong.

If you know why this is the answer and how to do it better please answer and Ill change the answer to yours.

Community
  • 1
  • 1
owen gerig
  • 6,026
  • 6
  • 48
  • 85
  • another interesting point is that the jar is still not on the class path (only the library project) is included. meening that it seems like for runtime class files its looking in the /libs dir? – owen gerig Aug 22 '12 at 02:05
1

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.