how can I add the aidl file to Android studio (fro

2019-01-04 21:37发布

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:

10条回答
别忘想泡老子
2楼-- · 2019-01-04 22:27

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

查看更多
你好瞎i
3楼-- · 2019-01-04 22:28

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

查看更多
三岁会撩人
4楼-- · 2019-01-04 22:28

Add this code in build.gradle

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

Rebuild and import aidl class

查看更多
够拽才男人
5楼-- · 2019-01-04 22:29

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.

查看更多
登录 后发表回答