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

Update gen_aidl documentation #103

Closed
benkc opened this issue Apr 11, 2014 · 8 comments
Closed

Update gen_aidl documentation #103

benkc opened this issue Apr 11, 2014 · 8 comments
Assignees

Comments

@benkc
Copy link

benkc commented Apr 11, 2014

I'm not sure if this is just a bug in the documentation, or a bug in the gen_aidl rule itself. The documentation for gen_aidl() is pretty sparse. I did however find an example in this previous issue:
#29

There's mention both there and in the docs of deprecating the gen_aidl() rule and making android_library handle aidl files, but my testing indicates that hasn't been done. (android_library() seems to completely ignore .aidl files in its srcs.)

The documentation and example both indicate that the 'aidl' argument has to be a single .aidl file. Does this mean I need a gen_aidl rule for each of my .aidl files? I've tried putting a glob there, but that results in a CoerceFailedException.

The more problematic thing is the import_path argument. The example in issue 29 shows it being the path to the directory that the .aidl file is in; however, I have found that while the 'aidl' argument is relative to the BUCK file, the import_paths argument is relative to the .buckconfig file. Moreover, regardless of what directory I put there, I (at best) get errors of the form:

couldn't find import for class com.blah.blah.blah.ipc.RemoteableFooBar

RemoteableFooBar is an aidl file in the same directory as the .aidl file I've pointed my 'aidl' argument at, which is also sometimes the same directory that I have import_path set to.

I've tried making my gen_aidl rule point at one of the above RemoteableFooBar.aidl files instead, but then the build says:
aidl can only generate code for interfaces, not parcelables or flattenables,
.aidl files that only declare parcelables or flattenablesmay not go in the Makefile.

I'm not sure what import_path should point to, but I've found it can only be a single path (not a glob or array or colon-separated), and the example shows it pointing to the same directory as the aidl file. Regardless of where I point it, I get the error that it couldn't find imports. (Or sillier errors, like that the directory I'm in doesn't exist if I leave it blank.)

@benkc
Copy link
Author

benkc commented Apr 11, 2014

I got it (kind of) working. Below is a stripped-down, commented version of what I ended up doing. I don't know when the plan is for deprecating the gen_aidl rule, but in the meantime, putting something like this in the documentation would be good.

android_library(
  name = 'foo_service_debug',
  visibility = ['PUBLIC'],
  srcs = glob(['Android/src/**/*.java'])  + \
  # Also include the generated .java files as sources.
  [genfile(f) for f in [
      'Android/src/com/blah/blah/blah/ipc/IFoo.java',
      'Android/src/com/blah/blah/blah/ipc/IBar.java',
      'Android/src/com/blah/blah/blah/ipc/IBaz.java',
      # ...and so on...
  ]],

  deps = [
          ':aidl_1',
          ':aidl_2',
          ':aidl_3',
          # ...and so on...
         ],
)

# AIDL stuff is tricky in BUCK.
# 1) Each gen_aidl rule can seemingly only process one .aidl file
# 2) The import_path is relative to where you run buck from (ie,
#    trunk, where the .buckconfig file is) not relative to the BUCK
#    file like all other buck paths
# 3) The import_path must point to the root of the src dir that the
#    .aidl files are somewhere under.  ie, Android/src, not
#    Android/src/com/blah/blah/blah/ipc
# Handy reference links:
# https://github.com/facebook/buck/issues/29
# https://github.com/facebook/buck/issues/103
# http://stackoverflow.com/questions/2179453/how-do-i-use-aidl-tool-from-command-line-using-sdk-sample-code

gen_aidl(
    name = 'aidl_1',
    aidl = 'Android/src/com/blah/blah/blah/ipc/IFoo.aidl',
    import_path = 'libs/foo_service/Android/src/',
)

gen_aidl(
    name = 'aidl_2',
    aidl = 'Android/src/com/blah/blah/blah/ipc/IBar.aidl',
    import_path = 'libs/foo_service/Android/src/',
)

gen_aidl(
    name = 'aidl_3',
    aidl = 'Android/src/com/blah/blah/blah/ipc/IBaz.aidl',
    import_path = 'libs/foo_service/Android/src/',
)

# ...and so on...

Edit: updated example to include the genfile part, that I was missing.

@shs96c
Copy link
Contributor

shs96c commented May 13, 2014

Hi,

Agreed, the aidl stuff is confusing. The import_path is particularly nasty,
for the reason you pointed out: it doesn't adhere to the conventions of the
rest of Buck. It's one of the older parts of the codebase, so I'd expect it
to be easier to clean up now than it was when we wrote it initially.

I'll use your tips to improve the quality of the existing docs, if that's
okay. If you're interested in contributing, this might be a fun thing to
look at. :)

Regards,

Simon

On Fri, Apr 11, 2014 at 9:24 PM, benkc notifications@github.com wrote:

I got it working. Below is a stripped-down, commented version of what I
ended up doing. I don't know when the plan is for deprecating the gen_aidl
rule, but in the meantime, putting something like this in the documentation
would be good.

android_library(
name = 'foo_service_debug',
visibility = ['PUBLIC'],
srcs = glob(['Android/src/*/.java']),
deps = [
':aidl_1',
':aidl_2',
':aidl_3',

...and so on...

],
)
AIDL stuff is tricky in BUCK. 1) Each gen_aidl rule can seemingly only
process one .aidl file 2) The import_path is relative to where you run
buck from (ie, trunk, where the .buckconfig file is) not relative to the
BUCK file like all other buck paths 3) The import_path must point to the
root of the src dir that the .aidl files are somewhere under. ie,
Android/src, not Android/src/com/blah/blah/blah/ipc Handy reference links:
#29 #29 #103#103
http://stackoverflow.com/questions/2179453/how-do-i-use-aidl-tool-from-command-line-using-sdk-sample-code

gen_aidl(
name = 'aidl_1',
aidl = 'Android/src/com/blah/blah/blah/ipc/IFoo.aidl',
import_path = 'libs/foo_service/Android/src/',
)

gen_aidl(
name = 'aidl_2',
aidl = 'Android/src/com/blah/blah/blah/ipc/IBar.aidl',
import_path = 'libs/foo_service/Android/src/',
)

gen_aidl(
name = 'aidl_3',
aidl = 'Android/src/com/blah/blah/blah/ipc/IBaz.aidl',
import_path = 'libs/foo_service/Android/src/',
)
...and so on...


Reply to this email directly or view it on GitHubhttps://github.com//issues/103#issuecomment-40249493
.

@sdwilsh
Copy link
Contributor

sdwilsh commented Jun 5, 2015

Actually, it looks like @shs96c never got around to updating these docs.

@sdwilsh sdwilsh reopened this Jun 5, 2015
@sdwilsh sdwilsh changed the title Can't get gen_aidl to work Update gen_aidl documentation Jun 5, 2015
@winterDroid
Copy link

So the genfile command does not exist anymore. Can you update the example? I try to import the OpenCV4Android SDK and am stuck on the aidl stuff.

Here is my configuration:

android_library(
  name = 'lib',
  srcs = glob(['**/*.java']),
  manifest = '//res/org/opencv:manifest',
  deps = [
    '//res/org/opencv:res',
    ':aidl',
  ],
  visibility = [ 'PUBLIC' ],
)

gen_aidl(
    name = 'aidl',
    aidl = 'engine/OpenCVEngineInterface.aidl',
    import_path = 'java/org/opencv/',
)

project_config(
  src_target = ':lib',
)

In IntelliJ everything gets displayed correctly, but I am not able to build with buck because OpenCVEngineInterface can't be found.

@winterDroid
Copy link

I just found a way to get it working:

android_library(
  name = 'lib',
  srcs = glob(['**/*.java']),
  manifest = '//res/org/opencv:manifest',
  deps = [
    '//res/org/opencv:res',
    ':opencv_aidl',
  ],
  visibility = [ 'PUBLIC' ],
)

android_library(
  name = 'opencv_aidl',
  srcs = [':aidl'],
)

gen_aidl(
    name = 'aidl',
    aidl = 'engine/OpenCVEngineInterface.aidl',
    import_path = 'java/',
)

project_config(
  src_target = ':lib',
)

Is that the intended way to do it?

EDIT: Unfortunately I'm now not able to install the app because of INSTALL_FAILED_DEXOPT

@mkosiba
Copy link
Contributor

mkosiba commented Apr 1, 2016

That looks about right. I don't think you need the intermediate android_library :

android_library(
  name = 'lib',
  srcs = glob(['**/*.java']) + [':aidl'],
  manifest = '//res/org/opencv:manifest',
  deps = [
    '//res/org/opencv:res',
  ],
  visibility = [ 'PUBLIC' ],
)
gen_aidl(
    name = 'aidl',
    aidl = 'engine/OpenCVEngineInterface.aidl',
    import_path = 'java/',
)

Not sure about the INSTALL_FAILED_DEXOPT error, adb logcat should have some details about why it's happening.

@winterDroid
Copy link

@marcinkosiba Thanks! Yeah I figured out that the INSTALL_FAILED_DEXOPT is just happening on Genymotion but not on my real device. Not sure why. Thanks!

@sdwilsh
Copy link
Contributor

sdwilsh commented Jan 12, 2017

It looks like the documentation largely matches what was found here today. I'll add @marcinkosiba's example as an example on that page now and add some text to clarify the root.

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

Successfully merging a pull request may close this issue.

6 participants