IT TIP

Google 인앱 결제, IllegalArgumentException : Android L Dev Preview로 업그레이드 한 후 서비스 의도가 명시 적이어야합니다.

itqueen 2020. 12. 26. 16:23
반응형

Google 인앱 결제, IllegalArgumentException : Android L Dev Preview로 업그레이드 한 후 서비스 의도가 명시 적이어야합니다.


Android L Dev Preview로 업그레이드 할 때까지 인앱 결제 코드가 제대로 작동했습니다. 이제 앱이 시작될 때이 오류가 발생합니다. 이 문제를 일으키는 L에 대해 무엇이 변경되었는지 또는이 문제를 해결하기 위해 코드를 어떻게 변경해야하는지 아는 사람이 있습니까?

android {
compileSdkVersion 'android-L'
buildToolsVersion '20'
defaultConfig {
    minSdkVersion 13
    targetSdkVersion 'L'
...
...


compile 'com.google.android.gms:play-services:5.+'
compile 'com.android.support:support-v13:21.+'
compile 'com.android.support:appcompat-v7:21.+'
...
...

앱 시작시 오류 :

06-29 16:22:33.281    5719-5719/com.tbse.wnswfree D/AndroidRuntime﹕ Shutting down VM
06-29 16:22:33.284    5719-5719/com.tbse.wnswfree E/AndroidRuntime﹕ FATAL EXCEPTION: main
Process: com.tbse.wnswfree, PID: 5719
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.tbse.wnswfree/com.tbse.wnswfree.InfoPanel}: java.lang.IllegalArgumentException: Service Intent must be explicit: Intent { act=com.android.vending.billing.InAppBillingService.BIND }
        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2255)
        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2317)
        at android.app.ActivityThread.access$800(ActivityThread.java:143)
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1258)
        at android.os.Handler.dispatchMessage(Handler.java:102)
        at android.os.Looper.loop(Looper.java:135)
        at android.app.ActivityThread.main(ActivityThread.java:5070)
        at java.lang.reflect.Method.invoke(Native Method)
        at java.lang.reflect.Method.invoke(Method.java:372)
        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:836)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:631)
 Caused by: java.lang.IllegalArgumentException: Service Intent must be explicit: Intent { act=com.android.vending.billing.InAppBillingService.BIND }
        at android.app.ContextImpl.validateServiceIntent(ContextImpl.java:1603)
        at android.app.ContextImpl.bindServiceCommon(ContextImpl.java:1702)
        at android.app.ContextImpl.bindService(ContextImpl.java:1680)
        at android.content.ContextWrapper.bindService(ContextWrapper.java:528)
        at com.tbse.wnswfree.util.IabHelper.startSetup(IabHelper.java:262)
        at com.tbse.wnswfree.InfoPanel.onStart(InfoPanel.java:709)
        at android.app.Instrumentation.callActivityOnStart(Instrumentation.java:1217)
        at android.app.Activity.performStart( Activity.java:5736)
        at android.app.ActivityThread.performLaunchActivity( ActivityThread.java:2218)
        at android.app.ActivityThread.handleLaunchActivity( ActivityThread.java:2317)
        at android.app.ActivityThread.access$800( ActivityThread.java:143)
        at android.app.ActivityThread$H.handleMessage( ActivityThread.java:1258)
        ...

           

InfoPanel.java의 709 행 :

        mHelper.startSetup(new IabHelper.OnIabSetupFinishedListener() {
          @Override
          public void onIabSetupFinished(IabResult result) {
            ...

나는 같은 문제가 있었고 패키지를 명시 적으로 설정하여 해결했습니다. Aleksey의 답변과 비슷하지만 더 간단합니다.

Intent intent = new Intent("com.android.vending.billing.InAppBillingService.BIND");
// This is the key line that fixed everything for me
intent.setPackage("com.android.vending");

getContext().bindService(intent, serviceConnection, Context.BIND_AUTO_CREATE);

아래 답변에서 지적했듯이 해결책은 명시 적 의도를 수동으로 만드는 것입니다.

private Intent getExplicitIapIntent() {
        PackageManager pm = mContext.getPackageManager();
        Intent implicitIntent = new Intent("com.android.vending.billing.InAppBillingService.BIND");
        List<ResolveInfo> resolveInfos = pm.queryIntentServices(implicitIntent, 0);

        // Is somebody else trying to intercept our IAP call?
        if (resolveInfos == null || resolveInfos.size() != 1) {
            return null;
        }

        ResolveInfo serviceInfo = resolveInfos.get(0);
        String packageName = serviceInfo.serviceInfo.packageName;
        String className = serviceInfo.serviceInfo.name;
        ComponentName component = new ComponentName(packageName, className);
        Intent iapIntent = new Intent();
        iapIntent.setComponent(component);
        return iapIntent;
    }

다음 은 명시 적 의도 확인을위한 L 미리보기 소스의 코드입니다. 현재 주석달렸 지만 L 미리보기가있는 Nexus 5에서는 여전히 실행되고 암시 적 의도에 대한 예외가 발생합니다.


Edit: @alav's answer is much more better and simpler. Just add

intent.setPackage("com.android.vending");

All credits for him. And here is the code in L release sources for check explicit intent.


Found clear solution here: https://code.google.com/p/android-developer-preview/issues/detail?id=1674

In Google Licensing Library (LVL), LicenseChecker.java file, replace "bindService" call with this:

 Intent serviceIntent = new Intent(
         new String(Base64.decode("Y29tLmFuZHJvaWQudmVuZGluZy5saWNlbnNpbmcuSUxpY2Vuc2luZ1NlcnZpY2U=")));
         serviceIntent.setPackage("com.android.vending");

     boolean bindResult = mContext
             .bindService(
               serviceIntent,
               this, // ServiceConnection.
               Context.BIND_AUTO_CREATE);

AND in the AndroidManifest.xml set: android:minSdkVersion="4"

The "setPackage" requires Android version 4.


In "L" binding to a service requires using an explicit intent.

See http://commonsware.com/blog/2014/06/29/dealing-deprecations-bindservice.html


Just replace the code

boolean attempt = mContext.bindService(new Intent("com.android.vending.billing.InAppBillingService.BIND"),
                mServiceConn, Context.BIND_AUTO_CREATE);

with the following code

Intent serviceIntent = new Intent("com.android.vending.billing.InAppBillingService.BIND");
        serviceIntent.setPackage("com.android.vending");
        boolean attempt = mContext.bindService(serviceIntent, mServiceConn, Context.BIND_AUTO_CREATE);

in the class IabHelper which you have placed in the inappbilling's utils folder (if you have followed the instruction of Google InApp Billing tutorial).


I was getting the same error from older Google Cloud Messaging setup code. The simplest fix appears to be changing

Intent registrationIntent = new Intent(
        "com.google.android.c2dm.intent.REGISTER");

into

Intent registrationIntent = new Intent();
registrationIntent.setClassName("com.google.android.c2dm.intent", "REGISTER");

For me it worked to use the current IabHelper from the samples: sdk/extras/google/play_billing/samples/TrivialDrive/src/com/example/android/trivialdrivesample/util/IabHelper.java

Don't forget to run the sdk update manager first to make sure that you have the current version installed.


The answers for this specific problems have already been posted, but just to help out others with the exact same problem, but this time for the Licence API.

You get the same error on 5.0 message as in the IAP library posted above, but you can find a fix (involving manually changing a few lines in LicenseChecker.java (Google's code) and then recompiling your project that will include this library).

Check out: https://code.google.com/p/android/issues/detail?id=78505 for details. Hope anyone can use it.


This worked for me but I'd like to know of it's an acceptable way to do this:

i.setClass(context, MyService.class);


if you have below error please set targetSdkVersion 19 in the build.gradle. When i set 19 my problem solved. For publish i set targetSdkVersion 27

at com.google.android.vending.licensing.LicenseChecker.checkAccess(LicenseChecker.java:150) at com.google.android.vending.expansion.downloader.impl.DownloaderService$LVLRunnable.run

defaultConfig {
    applicationId "com.brain.math.game.free"
    minSdkVersion 15
    targetSdkVersion 19 

targetSdkVersion 19

ReferenceURL : https://stackoverflow.com/questions/24480069/google-in-app-billing-illegalargumentexception-service-intent-must-be-explicit

반응형