how can I add the aidl file to Android studio (from the in-app billing example)

那年仲夏 提交于 2019-11-26 18:26:22

Just as the error message says, you need to put IInAppBillingService.aidl in the correct directory dictated by it's package (com.android.vending.billing).

Within the src/main/aidl/ folder you already have, put the .aidl file in com/android/vending/billing/.

Kalel Wade

Adding this as an answer since it seemed to help quite a few people.

  1. Create a new directory named 'aidl' under 'src/main/'. It should look like 'src/main/aidl'.
  2. Add a new package name 'com.android.vending.billing' to the directory 'src/main/aidl'
  3. Locate your sdk location and go to "sdk\extras\google\play_billing". Default location for the sdk is "C:\Program Files (x86)\Android\android-sdk". If you custom changed it, then you will have to figure out the location through the sdk manager.
  4. Copy 'IInAppBillingService.aidl' into the package created above. In the end, it should look similar to the image below.

  1. Rebuild project and it should be good to go.

Note: Make sure you include the necessary import if your reference isn't working

import com.android.vending.billing.IInAppBillingService;

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

Edit From Comment

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.

I've tried every solutions, but the problem was that Android Studio had compiled, with any apparent reason, in a different build type of the module that contains the AIDL packages than it was specified by the settings. From debug to release, so the other modules couldn't see the AIDL pkg. Switching from debug to release and turns back, solved my problem.

restarting Android Studio worked for me

a second silly thing that took me a while. I dropped the code on Android Studio to allow him create the file, but he created a .java (as expected) instead a .aidl Jiji, stupid of me

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!