docs icon indicating copy to clipboard operation
docs copied to clipboard

More generic solution for integration conan in gradle build system for Android projects

Open CAMOBAP opened this issue 5 years ago • 7 comments

Problem

https://docs.conan.io/en/latest/integrations/android_studio.html page provides a solution for a single ABI project, if you need to support x86 or arm64-v8a this will not work out of box

Proposed solution

I have implemented a simple Gradle plugin for Android NDK CMake project https://gist.github.com/CAMOBAP795/ed9aa6a7549787b5eea4b2048b896747

At this time it supports CMake only, but I think it should be enough

I ready to get some feedback/critics )

CAMOBAP avatar Apr 27 '19 16:04 CAMOBAP

I don't know how that gradle plugin work, but I think it would just change the profile to use when compiling for a different architecture (String profile = 'android-${abi}'), right?

danimtb avatar Apr 29 '19 15:04 danimtb

@danimtb close to truth

Plugin user will need to:

  1. Include plugin into build.gradle with apply from: "${rootDir}/conan.gradle" command
  2. Configure plugin with
conan {
    conanfile = 'src/main/cpp/conanfile.txt'
    profile = 'android-${abi}'
}

Where profile is template string for conan profile which will depends on abi (in fact it's template string and abi can be skipped

CAMOBAP avatar Apr 29 '19 15:04 CAMOBAP

I understand that this automates some parts for changing the arch without changing anything, just building the project for the desired arch (probably selecting that in the Android Studio IDE).

However, I am not sure if this plugin will make the example you linked above (still works for just one arch) more clear...

At least you only need to have the profiles in the profiles folder with the right naming as stated above profile = 'android-${abi}'}

danimtb avatar Apr 29 '19 15:04 danimtb

I understand that this automates some parts for changing the arch without changing anything, just building the project for the desired arch (probably selecting that in the Android Studio IDE).

This configured on Gradle config level in build.gradle, abiFilters in https://gist.github.com/CAMOBAP795/ed9aa6a7549787b5eea4b2048b896747 , gradle just do build for each declared abi

However, I am not sure if this plugin will make the example you linked above (still works for just one arch) more clear...

I have tried to keep it as simple as possible, from another point I tried to handle possible error cases too return clear messages too...

Anyway I'm ready to improve it or answer any questions

At least you only need to have the profiles in the profiles folder with the right naming as stated above profile = 'android-${abi}'}

I thought about using a dictionary (like {'armeabi-v7a: 'profile_armv7', 'x86': 'profile_x86'}) instead of the template string.

Also, there are no restrictions to keep a profile in ~/.conan/profiles, firstly plugin check profile relative to current build.gradle plugin

CAMOBAP avatar Apr 29 '19 15:04 CAMOBAP

I see... Thanks a lot for the clarification. We could add a link to your repo with the gradle plugin to the integrations section

danimtb avatar Apr 29 '19 16:04 danimtb

Any update on this? The gists is not available. I struggling with the same issue.

jngd avatar Feb 05 '21 12:02 jngd

Actual gist link https://gist.github.com/CAMOBAP/ed9aa6a7549787b5eea4b2048b896747

CAMOBAP avatar Dec 27 '21 21:12 CAMOBAP