143

I am currently migrating an Eclipse app to Android Studio. This app was using the in app billing.

My main problem is to compile the project and the aidl file (I guess you all use this file)

I get this error message:

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

So, following some tutorials, I move this file from com.mypackage.billing to src/main/aidl (see this reference)

But as soon, as I do that, I get this message:

Gradle: Execution failed for task ':xxxxxxxxxxx:compileDebugAidl'.

Failed to run command: (...) C:\Users\xxxx\AndroidStudioProjects\xxxxxxProject\xxxxxxx\src\main\aidl\IInAppBillingService.aidl:45 interface IInAppBillingService should be declared in a file called com\xxxxxxxx\billing\IInAppBillingService.aidl.

The message is clearly a contradiction with the post from the Google bug page I linked above.

Anyone suceeded to make this aidl file to work and can help me?

enter image description here

Just to inform, some links I followed:

Ahmad Aghazadeh
  • 16,571
  • 12
  • 101
  • 98
Waza_Be
  • 39,407
  • 49
  • 186
  • 260
  • question is ... shouldn't be this aidl file in `/src/main/aidl/com/android/vending/billing` ? – Selvin Jul 24 '13 at 14:10
  • 1
    Gradle: Execution failed for task ':MyProject:compileDebugAidl'. > Failed to run command: 45 interface IInAppBillingService should be declared in a file called com\android\vending\billing\IInAppBillingService.aidl. – Waza_Be Jul 24 '13 at 14:16
  • 1
    something tells me you're still not putting it in the folder that Selvin and I are saying...? – Sam Dozor Jul 24 '13 at 14:21
  • just added a new screenshot, I think I put it in the folder you told me.. – Waza_Be Jul 24 '13 at 14:28
  • http://selvin.pl/TrivialDriveProject.Gradle.zip (change sdk dir in local.properties) ... `gradlew.bat assemble` and it works like a charm ... are you sure that folder is /src/main/aidl/com/android/vending/billing not /src/main/aidl/com.android.vending.billing ? AS 0.2.1 ? Gradle 0.5.+ ? – Selvin Jul 24 '13 at 14:34
  • Have you solved the problem? I have the same issue here. – Bagusflyer Aug 19 '13 at 07:51
  • Sorry. I found my problem. It's still the path. – Bagusflyer Aug 19 '13 at 07:59

13 Answers13

233

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.

Screenshot of result

  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

Kaushal28
  • 5,377
  • 5
  • 41
  • 72
Kalel Wade
  • 7,742
  • 3
  • 39
  • 55
  • 1
    Just to be clear: read this thoroughly! I didn't...to emphasize again: It IS a good addition...PUT THE com.android.vending.billing IN THE NEW 'main/aidl' directory! – Boy Jul 22 '14 at 14:11
  • 6
    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. – arlomedia Sep 18 '14 at 20:49
  • This worked, but why isn't this all automatic, when you choose to add the module? – android developer Dec 10 '14 at 22:46
  • Thanks for the rebuild project tip. Also the folder and package can be created in a flavor, it doesn't have to be in main. (If for example you only do in app billing in one flavor of your app) – Mike Fosker Dec 11 '14 at 11:19
  • 4
    Spent 20 minutes trying to solve this problem until I came to your answer. Then I tried to upvote it to get the error "You last voted on this answer..." I guess some people never learn :) – beetree Dec 27 '14 at 00:04
  • I'd have given the green check to this answer for the illustration (worth a thousand words). – Androidcoder Jun 17 '15 at 13:31
  • Can you tell me about step "3" ? I don't understand –  Jul 23 '15 at 08:07
  • @delive Step number 3 refers to the android sdk that is downloaded. I Believe the default location is C:\Program Files (x86)\Android\android-sdk. It depends on what version you installed and if you changed it. Then navigate to the location in step 3 and get the file (step 4) – Kalel Wade Jul 23 '15 at 15:25
  • putting these 9 files in same directory with `MainActivity.class` worked for me! I didn't put them in `util` folder. – Mehrdad Salimi May 25 '16 at 11:17
  • the aidl documentation says "save your .aidl file in your project's src/ directory and when you build your application, the SDK tools generate the IBinder interface file in your project's gen/ directory. The generated file name matches the .aidl file name, but with a .java extension". I got error on doing this, there is no gen folder I could see. Something told me there may be an aidl folder, which led me to this excellent answer, the error vanished. – amitava Feb 17 '19 at 20:07
  • This worked for me on android studio 4.2 C15 using SDK 30. Keep in mind after the rebuilt the error may take some time to go away 1-2min or so. so be patient! – Miguel Tomás Mar 03 '21 at 12:47
166

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/.

Sam Dozor
  • 40,335
  • 6
  • 42
  • 42
  • 5
    When I do this, I get: Gradle: error: cannot find symbol class IInAppBillingService – Waza_Be Jul 24 '13 at 14:13
  • 9
    so it's in /src/main/aidl/com/android/vending/billing? Are you using gradle to build? If so, hit the little gradle button at the top right of Android Studio to have gradle reload configuration, or close/open Android Studio. – Sam Dozor Jul 24 '13 at 14:16
  • I used gradle to build, and updated screenshot shows you the folder in question – Waza_Be Jul 24 '13 at 14:35
  • are you specifying a custom location for your aidl in your build.gradle? – Sam Dozor Jul 24 '13 at 14:48
  • 80
    Just to clarify. Create a directory aidl under src/main/. Then add a new package com.android.vending.billing. Then copy the aidl file into the new package. See https://code.google.com/p/android/issues/detail?id=56755 – Kalel Wade Jul 26 '13 at 19:08
  • 2
    @Kalel Wade This was the solution for me, you should add it as an answer. – eski Mar 13 '14 at 02:53
  • 3
    If you don't have src/main, create the aidl directory anywhere and specify in build.gradle: android { sourceSets { main { aidl { srcDirs 'actual_path..' – aleb May 19 '14 at 08:29
  • This doens't work for me. I allready have this structure and still get the same error. – Christoffer Jun 04 '15 at 04:43
  • If it's not working, you need to ACTUALLY MAKE the folders and not just create packages. – Jessicardo Feb 16 '16 at 06:06
11
  • 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.
Praveena
  • 6,340
  • 2
  • 40
  • 53
  • After copying file "IInAppBillingService.aidl", is it required to change any line of this file ? I have seen some notes asking to replace the package name as it is coming from a sample to avoid error "aidl.exe' finished with non-zero exit value 1". What are the specific instructions to do this ? – Pablo Alfonso Mar 08 '19 at 15:20
11

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

enter image description here

zeeawan
  • 6,667
  • 2
  • 50
  • 56
10

Add this code in build.gradle

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

Rebuild and import aidl class

Ahmad Aghazadeh
  • 16,571
  • 12
  • 101
  • 98
2

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.

Nicholas
  • 1,974
  • 4
  • 20
  • 46
1

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

Aag1189
  • 177
  • 12
1

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.

Community
  • 1
  • 1
0

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.

0

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

pellyadolfo
  • 981
  • 10
  • 23
0

if you do all the names correct go to Build>rebuild project it worked for me

0

I use Android Studio 4.1, just right click mouse -> New -> AIDL -> AIDL File. A file will be created and placed in the [src/main/aidl] folder automatically. The aidl folder will also be created if it does not exist.

This function only supports min sdk 16+. My old project still can be supported, you can temporarily modify the min sdk to 16, create aidl and build project. After the relative interface and class be generated, recover the min sdk settings, it also works and builds project well then.

Shrdi
  • 359
  • 4
  • 13
0

This answer might not exactly be for the question posted but may help others having issues related to creating AIDL folder. Sometimes the AIDL folder doesn't show in Android Studio even if we create like app > New > Folder > AIDL Folder. The folder exists in file explorer but doesn't show or detect in Android Studio.

I had this issue and I've solved it using the following steps

Step 1: Open the gradle.properties file and add the android.defaults.buildfeatures.aidl=true at the end of this file as shown in the screenshot. enter image description here

Step 2: Right Click on the app folder it will show a window do the following flow app > New > Folder > AIDL Folder enter image description here

Step 3: Click the Finish button enter image description here The AIDL folder is now created and shown in Android Studio enter image description here

AtifSayings
  • 756
  • 14
  • 23