Skip to content
This repository has been archived by the owner on Nov 10, 2023. It is now read-only.

Error building AIDL files as part of build #271

Closed
amitkot opened this issue Mar 8, 2015 · 14 comments
Closed

Error building AIDL files as part of build #271

amitkot opened this issue Mar 8, 2015 · 14 comments

Comments

@amitkot
Copy link

amitkot commented Mar 8, 2015

I have a couple of AIDL files in a directory that contains both them and Java files.
Following the AntennaPod tutorial, I created the following BUCK file for my project:

import re

jar_deps = []
for jarfile in glob(['libs/*.jar']):
    name = 'jars__' + re.sub(r'^.*/([^/]+)\.jar$', r'\1', jarfile)
    jar_deps.append(':' + name)
    prebuilt_jar(
        name = name,
        binary_jar = jarfile,
    )

android_library(
    name = 'all-jars',
    exported_deps = jar_deps,
)

proj_gen_aidls = []
for aidlfile in glob(['src/main/java/**/*.aidl']):
    name = 'proj_aidls__' + re.sub(r'^.*/([^/]+)\.aidl$', r'\1', aidlfile)
    proj_gen_aidls.append(':' + name)
    gen_aidl(
        name = name,
        aidl = aidlfile,
        import_path = 'src',
)

android_library(
    name = 'proj-aidls',
    srcs = proj_gen_aidls,
)

android_build_config(
    name = 'build-config',
    package = 'com.mobile.proj',
)


android_resource(
    name = 'res',
    package = 'com.mobile.proj',
    res = 'res',
    assets = 'assets',
    deps = [
    ]
)

android_library(
    name = 'main-lib',
    srcs = glob(['src/main/java/**/*.java']),
    deps = [
        ':all-jars',
        ':proj-aidls',
        ':build-config',
        ':res',
    ],
)

keystore(
    name = 'debug_keystore',
    store = 'keystore/debug.keystore',
    properties = 'keystore/debug.keystore.properties',
)

android_binary(
    name = 'proj',
    manifest = 'AndroidManifest.xml',
    target = 'android-10',
    keystore = ':debug_keystore',
    deps = [
        ':main-lib',
    ],
)

When I run buck build proj I get the following errors:

src/main/java/com/mobile/proj/domain/VehicleState.aidl:4 aidl can only generate code for interfaces, not parcelables or flattenables,
src/main/java/com/mobile/proj/domain/VehicleState.aidl:4 .aidl files that only declare parcelables or flattenablesmay not go in the Makefile.
src/main/java/com/mobile/proj/be/api/ControlService.aidl:3: couldn't find import for class com.mobile.proj.domain.TripState
src/main/java/com/mobile/proj/be/api/ControlService.aidl:4: couldn't find import for class com.mobile.proj.domain.BackendServiceState
src/main/java/com/mobile/proj/be/api/ControlService.aidl:5: couldn't find import for class com.mobile.proj.domain.VehicleState
src/main/java/com/mobile/proj/domain/BackendServiceState.aidl:4 aidl can only generate code for interfaces, not parcelables or flattenables,
src/main/java/com/mobile/proj/domain/BackendServiceState.aidl:4 .aidl files that only declare parcelables or flattenablesmay not go in the Makefile.
src/main/java/com/mobile/proj/domain/TripState.aidl:4 aidl can only generate code for interfaces, not parcelables or flattenables,
src/main/java/com/mobile/proj/domain/TripState.aidl:4 .aidl files that only declare parcelables or flattenablesmay not go in the Makefile.
BUILD FAILED: //:proj_aidls__VehicleState failed with exit code 1:
aidl

Any ideas?

@amitkot
Copy link
Author

amitkot commented Mar 9, 2015

I have some more insights. Out of the four AIDL files, it seems 3 only contain parcelable objects (as the error describes), which leaves us with only one AIDL file to be handled - ControlService.aidl .

I made the minimal changes to the BUCK file so that it will handle only that AIDL file:

proj_gen_aidls = []
for aidlfile in glob(['src/main/java/**/ControlService.aidl']):
    name = 'proj_aidls__' + re.sub(r'^.*/([^/]+)\.aidl$', r'\1', aidlfile)
    proj_gen_aidls.append(':' + name)
    gen_aidl(
        name = name,
        aidl = aidlfile,
        import_path = 'src',
)

Now I am getting the following errors:

src/main/java/com/mobile/proj/be/api/ControlService.aidl:3: couldn't find import for class
com.mobile.proj.domain.TripState
src/main/java/com/mobile/proj/be/api/ControlService.aidl:4: couldn't find import for class
com.mobile.proj.domain.BackendServiceState
src/main/java/com/mobile/proj/be/api/ControlService.aidl:5: couldn't find import for class com.mobile.proj.domain.VehicleState

It looks as though the import_path doesn't reach those Java files, however, they are indeed located in the src directory:

$ ls -a .buckconfig
.buckconfig
$ find . | egrep 'BackendServiceState.java|TripState.java|VehicleState.java'
./src/main/java/com/mobile/proj/domain/BackendServiceState.java
./src/main/java/com/mobile/proj/domain/TripState.java
./src/main/java/com/mobile/proj/domain/VehicleState.java

So why isn't the gen_aidl() task able to import those java files?

@sdwilsh
Copy link
Contributor

sdwilsh commented May 15, 2015

This might be silly, but what if you set import_path to src/? That slash might actually matter.

@sdwilsh
Copy link
Contributor

sdwilsh commented May 15, 2015

This is the bit that makes me think that import_path is off: https://github.com/facebook/buck/blob/master/src/com/facebook/buck/android/GenAidl.java#L122

@sdwilsh
Copy link
Contributor

sdwilsh commented Jun 5, 2015

No response from @amitkot. If we get one, we can reopen this.

@sdwilsh sdwilsh closed this as completed Jun 5, 2015
@Piasy
Copy link

Piasy commented Feb 18, 2016

@sdwilsh Hi, I think the problem is that in @amitkot 's ControlService.aidl file, it imports a self defined data type, BackendServiceState I guess, while in BUCK build process, the aidl program complains that it won't generate for parcelables or flattenables, so BUCK fails.

And I also tried change src into src/, it makes no difference.

@Piasy
Copy link

Piasy commented Feb 19, 2016

@sdwilsh And I find that inside BUCK source code, when executing the aidl program, it adds -b option, which will fail when trying to compile a parcelable, I think that's the root cause of this problem. Besides, the import_path should point to where .aidl files locate, not where .java file locate, although they could be the same.

@Piasy
Copy link

Piasy commented Feb 19, 2016

@sdwilsh I create a reproduce project that could reproduce the AIDL support problem.

Inside the project root dir, execute buck build app/:src_debug, it fails with:

/Users/piasy/src/BuckAidlDemo/app/src/main/aidl/com/github/piasy/buckaidldemo/Person.aidl:3 aidl can only generate code for interfaces, not parcelables or flattenables,
/Users/piasy/src/BuckAidlDemo/app/src/main/aidl/com/github/piasy/buckaidldemo/Person.aidl:3 .aidl files that only declare parcelables or flattenablesmay not go in the Makefile.

When I use my self built BUCK with the modification of removing the -b option passing to aidl executable, to execute ../buck/bin/buck build app/:src_debug, it fails with:

/com/github/piasy/buckaidldemo/IMyAidlInterface.java:152: error: can't find symbol
public void sayHello(com.github.piasy.buckaidldemo.Person person) throws android.os.RemoteException;                                                  
                                                   ^

Obviously the javac execution didn't find my self implemented Person class, but gradle works perfectly. I haven't dig into BUCK source code deeply so I can't figure out how to fix the problem myself, hope you guys could fix it soon. :)

@sdwilsh sdwilsh reopened this Feb 19, 2016
@sdwilsh
Copy link
Contributor

sdwilsh commented Feb 19, 2016

@marcinkosiba might have so ideas on how to fix it then to help you submit a PR :)

@zuolongxiang
Copy link

I hope this bug could fix it soon.

@8enet
Copy link

8enet commented Mar 19, 2016

I cannot build,always receive same problem.

@loveguag
Copy link

a simple workaround:

  1. modify AidlStep.java, delete line 69:args.add("-b");
  2. build buck
  3. move your "self implemented Person" java file to an independent directory under project root : e.g parcelable/com/github/piasy/buckaidldemo/Person.java
  4. write a BUCK file in the same directory, content like this:
    android_library(
    name = 'parcelables',
    srcs = glob(['*.java']),
    visibility = [
    'PUBLIC'
    ],
    )

project_config(
src_target = ':parcelables',
)
5. modify your BUCK file which has section "gen_aidl" like this:
android_library(
name = 'test',
srcs = [':testperson'] + [':person'],
deps = ['//parcelable/com/github/piasy/buckaidldemo:parcelables'],
visibility = [
'PUBLIC'
],
)

gen_aidl(
name = 'testperson',
aidl = 'aidl/com/github/piasy/buckaidldemo/TestPerson.aidl',
import_path = 'aidl',
visibility = [
'PUBLIC'
],
)

gen_aidl(
name = "person",
aidl = 'aidl/com/github/piasy/buckaidldemo/Person.aidl',
import_path = 'aidl',
visibility = [
'PUBLIC'
],
)

project_config(
src_target = ':test',
)
6.enjoy it

@Piasy
Copy link

Piasy commented Apr 11, 2016

Sounds cool, I'll try it.

@Piasy
Copy link

Piasy commented Apr 11, 2016

@loveguag I have a better solution based on yours, see my demo project for full example:

0 . modify AidlStep.java, comment off line 69:args.add("-b") then build buck;

1 . Put all self implemented parcelable class inside a directory under app/src/main/parcelable;

2 . Add this rule into app/BUCK:

android_library(
    name = 'parcelables',
    srcs = glob([
        'src/main/parcelable/**/*.java',
    ]),
)

3 . Change the app_aidls rule to this:

android_library(
    name = 'app_aidls',
    srcs = gen_app_aidls,
    deps = [':parcelables'], // add dependency to :parcelables
)

4 . (To enable gradle works well at the same time) Add this line into app/build.gradle's android closure:

android {
    ...
    sourceSets {
        main.java.srcDirs += 'src/main/parcelable'
    }
}

5 . Enjoy!

Besides, I submitted a pr #708, hope @sdwilsh can process it soon.

After BUCK could compile aidl correctly, I'll update OkBuck to get fully aidl support too.

@loveguag
Copy link

Wonderful~
It's better if android support generating all java files from aidl file directly, but not bring out a special solution like now.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants