IT story

인앱 결제 예제에서 Android Studio에 보조 파일을 추가하는 방법

hot-time 2020. 6. 26. 07:55
반응형

인앱 결제 예제에서 Android Studio에 보조 파일을 추가하는 방법


현재 Eclipse 앱을 Android Studio로 마이그레이션하고 있습니다. 이 앱은 인앱 결제를 사용하고있었습니다.

내 주요 문제는 프로젝트와 보조 파일을 컴파일하는 것입니다 (모두이 파일을 사용한다고 생각 합니다 )

이 오류 메시지가 나타납니다.

Gradle: error: cannot find symbol class IInAppBillingService
Gradle: error: package IInAppBillingService does not exist

따라서 일부 자습서를 따르면이 파일을 com.mypackage.billing에서 src / main / aidl로 이동합니다 ( 이 참조 참조 )

그러나 그렇게하면 곧이 메시지가 나타납니다.

Gradle : 작업 ': xxxxxxxxxxx : compileDebugAidl'에 대한 실행이 실패했습니다.

명령을 실행하지 못했습니다 : (...) C : \ Users \ xxxx \ AndroidStudioProjects \ xxxxxxProject \ xxxxxxx \ src \ main \ aidl \ IInAppBillingService.aidl : 45 IInAppBillingService 인터페이스는 com \ xxxxxxxx \ billing \ IInAppBillingService 파일에 선언되어야합니다. .aidl.

이 메시지는 위에 링크 된 Google 버그 페이지의 게시물과 모순됩니다.

이 보조 파일을 작동시키는 데 성공하고 나를 도울 수있는 사람이 있습니까?

여기에 이미지 설명을 입력하십시오

정보를 제공하기 위해 내가 따라 간 일부 링크 :


오류 메시지에서 알 수 있듯이 IInAppBillingService.aidl패키지 (com.android.vending.billing)에 의해 지시 된 올바른 디렉토리에 넣어야 합니다.

src/main/aidl/이미 가지고 있는 폴더 안에 .aidl파일을 습니다 com/android/vending/billing/.


꽤 많은 사람들을 돕는 것처럼 보였으므로 이것을 대답으로 추가하십시오.

  1. 'src / main /'아래에 'aidl'이라는 새 디렉토리를 작성하십시오 . ' src / main / aidl ' 과 같아야 합니다.
  2. 새 패키지 이름 ' com.android.vending.billing '을 ' src / main / aidl ' 디렉토리에 추가하십시오.
  3. SDK 위치를 찾아 "sdk \ extras \ google \ play_billing"으로 이동하십시오. SDK의 기본 위치는 "C : \ Program Files (x86) \ Android \ android-sdk"입니다. 사용자 지정 변경 한 경우 SDK 관리자를 통해 위치를 파악해야합니다.
  4. 'IInAppBillingService.aidl' 을 위에서 만든 패키지에 복사하십시오 . 결국 아래 이미지와 비슷하게 보입니다.

결과 스크린 샷

  1. 프로젝트를 다시 빌드 하면 좋을 것입니다.

참고 : 참조가 작동하지 않는 경우 필요한 가져 오기를 포함하십시오

import com.android.vending.billing.IInAppBillingService;

https://issuetracker.google.com/issues/36973270

주석에서 편집

After I did this, the references to IInAppBillingService in my code were still highlighted as errors, but after rebuilding the app, the class was recognized


The rest of posts here didn't work for me till I created a new folder like shown here.

여기에 이미지 설명을 입력하십시오


  • Create new directory under src/main called aidl
  • Right click on directory aidl, select new->add package
  • Enter Name of the package com.android.vending.billing

  • Copy IInAppBillingService.aidl from the directory Android/Sdk/extras/google/play_billing to the directory App_name/app/src/main/aidl/com/android/vending/billing

  • Now go ahead with InApp billing coding and while defining InApp related services you will get an error can not resolve symbol IInAppBillingXXXXXX
  • Now goto to Build from android studio menu , click on Rebuild Project. This will generate IInAppBillingService.java file inside App_Name/app/build/generated/source/aidl/debug/com/android/vending/billing. This will solve the issue.

Add this code in build.gradle

android {
    sourceSets {
        main {
            aidl.srcDirs = ['src']
        }
    }
}

Rebuild and import aidl class


The above answers concentrate on file location, but it appears you already had that set correctly. I experienced this same issue in Android Studio, but none of the listed answers resolved it, and I banged my head against it for an hour. Eventually, I realized that I was missing an obvious import:

 import com.android.vending.billing.IInAppBillingService;

Once I added that it resolved this error message.

This import isn't mentioned in any of the Google Billing docs or included in any of the code examples that I found. While it may be obvious to experienced Java developers, beginners just trying to learn their first project may need it explicitly pointed out.


We need to add

  1. create folder - src/main/aidl/packagename and place aidl file under this.

  2. In the aidl file - mention the package name. package packagename

Now clean the project, rebuild the project - We can the corresponding java file for the aidl generated in app\build\generated\source\aidl\debug\packagename\youraidl.java


I know it sounds so easy, but I copy paste from google sample all folder

https://github.com/googlesamples/android-play-billing/tree/master/TrivialDrive/app/src/main

aidl/com/android/vending/billing

copied into project aidl ( I had set project view in Android Studio)

and next I clean and rebuild project and it found a reference.


모든 솔루션을 시도했지만 문제는 안드로이드 스튜디오가 AIDL 패키지가 포함 된 다른 빌드 유형의 모듈로 설정에 지정된 것과 다른 명백한 이유로 컴파일되었다는 것입니다. 디버그에서 릴리스 까지 다른 모듈은 AIDL pkg를 볼 수 없었습니다. 디버그에서 릴리스로 전환하고 다시 전환하면 내 문제가 해결되었습니다.


Android Studio를 다시 시작하면 나를 위해 일했습니다.

제게 시간이 걸렸다 파일을 만들 수 있도록 Android Studio에서 코드를 삭제했지만 예상대로 .java 대신 .aidl Jiji를 만들었습니다.

참고 URL : https://stackoverflow.com/questions/17836234/how-can-i-add-the-aidl-file-to-android-studio-from-the-in-app-billing-example

반응형