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

Get Core GL C++ Into Android Project #1753

Closed
bleege opened this issue Jun 18, 2015 · 52 comments
Closed

Get Core GL C++ Into Android Project #1753

bleege opened this issue Jun 18, 2015 · 52 comments
Labels
Android Mapbox Maps SDK for Android refactor

Comments

@bleege
Copy link
Contributor

bleege commented Jun 18, 2015

In order to support C++ / NDK debugging in Android Studio and streamline CI builds and artifact publication we need to refactor the current make android process to integrate the Core GL C++ project files into the Gradle managed Android project. The current process compiles the Core GL into .so files based on ABI and places them into jniLibs for the Gradle build process to then use as a separate step, while the new process will copy the uncompiled C++ files into jni and make (the Gradle driven) Android NDK responsible for compiling them and linking them via JNI to the Android code along with building the SDK as whole in one step. This process will essentially mirror what is done for iOS and Xcode with make iproj where Xcode is responsible for all the compilation and linking.

Unknowns

  • Will custom Android.mk files be needed or will the built in NDK controls in Gradle be enough.
  • Will current GL Makefile process work or will refactoring to use something like Bazel be needed?

Resources

@mapbox/mobile @mapbox/gl

@bleege bleege added refactor Android Mapbox Maps SDK for Android starter-task labels Jun 18, 2015
@bleege bleege added this to the Android Beta milestone Jun 18, 2015
@bleege
Copy link
Contributor Author

bleege commented Jun 18, 2015

What Before and After should look like:

20150618-current-jnilibs-to-new-jni

@mb12
Copy link

mb12 commented Jun 18, 2015

This would be really awesome when it is available. Is this already working in your local repo?
In this year's Google IO, they announced that Jetbrains NDK plugin will be available for free for Android development.

https://www.youtube.com/watch?v=f7ihSQ44WO0

@ljbade
Copy link
Contributor

ljbade commented Jun 19, 2015

Yeah I look forward to having everything in Studio too. At one point in time (June last year) I did actually have everything built with a custom Android.mk file but a lot has changed since.

Let me know if you need help with this @bleege. First I would try getting NDK to compile all the C++ files. If we can get that to work then the hardest bit will be getting everything linked nicely.

@bleege
Copy link
Contributor Author

bleege commented Jun 22, 2015

@ljbade Yeah, it'd be fantastic to get your 👀 on this.

First I would try getting NDK to compile all the C++ files.

Agreed. It's a little unclear to me how all the C++ and related dependencies would be compiled via NDK. I assume that Mason has to stay in the mix somewhere? Can you sketch out how you think this would work on a branch?

@ljbade
Copy link
Contributor

ljbade commented Jun 22, 2015

Hmm yeah we going to need mason. Can't think off the top of my head the best way to do this.

Perhaps we are going to need to create a series of custom Gradle tasks that somehow add dependencies and etc automatically from mason command calls into the NDK settings in the Gradle state.

@ljbade
Copy link
Contributor

ljbade commented Jun 23, 2015

This is my thinking so far:

  • gradle has custom task that copies C++ files to jni dir, perhaps by calling a gyp command that does this from the gyp files (it may be better to symlink though so you can edit the files in Android Studio?)
  • gradle has another custom task that runs the mason setup - this will install the deps, copy the libs to the jniLibs dir and also insert the required compiler and linker flags into the NDK compile config
  • gradle then uses normal NDK process to compile jni dir and link with jniLibs

@ljbade
Copy link
Contributor

ljbade commented Jun 23, 2015

@kkaefer How hard would it be to get gyp to copy or symlink the C++ files in the Android target instead of compiling them?

Is it also possible to capture the compile and linker flags set in gyp? Berhaps echoing them to stdout then gradle can grab them

@kkaefer
Copy link
Contributor

kkaefer commented Jun 23, 2015

Can we get around copying the files into the jni dir by specifying the paths in a (generated) Android.mk file?

@bleege
Copy link
Contributor Author

bleege commented Jun 23, 2015

@kkaefer Yep. We can point the NDK at what ever path we want to. The only potential issue is if the debugger will work like this, but that's more of an unknown as Google hasn't even released it in Android Studio yet. In other words, lets worry about that later.

My big blocker is just knowing what all needs to be compiled on the C++ side. If I can get pointed at the all the C++ needed I can then get the Gradle / NDK side wired up to start compiling things.

@bleege
Copy link
Contributor Author

bleege commented Jun 23, 2015

Internal discussion between @kkaefer and @bleege about the pieces involved with C++ compilation for Android.

@bleege
Copy link
Contributor Author

bleege commented Jun 23, 2015

According to this bug report Android generator is being removed from GYP.

@bleege
Copy link
Contributor Author

bleege commented Jun 23, 2015

After experimenting with gyp's -f android and being told to run lunch, I'm going to look into using Gradle to set a task to copy the C++ files into jni and compile from there. This seems like a more robust solution based on the GYP bug report ^^ from May 2015 about it being removed anyway. Does this seem reasonable @kkaefer @springmeyer?

Makefile/android-%: CMD = deps/run_gyp android/mapboxgl-app.gyp $(CONFIG_android-$*) $(LIBS_android) --generator-output=./build/android-$* -f android
deps/run_gyp android/mapboxgl-app.gyp -Dhost=android -Iconfig/android-arm-v7.gypi -Dheadless_lib=none -Dplatform_lib=android -Dasset_lib=zip -Dhttp_lib=curl -Dcache_lib=sqlite --depth=. -Goutput_dir=. --generator-output=./build/android-arm-v7 -f android
Traceback (most recent call last):
  File "deps/run_gyp", line 8, in <module>
    sys.exit(gyp.script_main())
  File "deps/gyp/pylib/gyp/__init__.py", line 534, in script_main
    return main(sys.argv[1:])
  File "deps/gyp/pylib/gyp/__init__.py", line 527, in main
    return gyp_main(args)
  File "deps/gyp/pylib/gyp/__init__.py", line 512, in gyp_main
    generator.GenerateOutput(flat_list, targets, data, params)
  File "deps/gyp/pylib/gyp/generator/android.py", line 969, in GenerateOutput
    assert android_top_dir, '$ANDROID_BUILD_TOP not set; you need to run lunch.'
AssertionError: $ANDROID_BUILD_TOP not set; you need to run lunch.
make: *** [Makefile/android-arm-v7] Error 1

@bleege
Copy link
Contributor Author

bleege commented Jun 24, 2015

Setting up the Copy C++ route. The build.gradle file will now copy in the basic C++ files (Android C++, Core GL, and Platform), while http, asset, and cache remain to be done.

After http, asset, and cache are done the next step will be to integrate the library dependencies as well as configure NDK to compile everything.

@bleege
Copy link
Contributor Author

bleege commented Jun 24, 2015

Reviewed http, asset and cache .gypi files and determined that they all are already included as part of the platform and android copy process. Future additions or removals in these directories should auto update as the copy processes (as currently) implemented grab default and android specific content (ie, no iOS stuff should ever be in these directories).

Will now look at setting up the basic NDK build process. This will include:

  1. Adding the C++ library dependencies
  2. Compiler Options like LDFLAGS

@bleege
Copy link
Contributor Author

bleege commented Jun 24, 2015

Added copying of Certs and Styles to assets directory in SDK file structure to the build file. This should be the last of the files that need to be transferred over AFAICT. The "current" view of what this looks like in the filesystem is the screen shot below.

20150624-current-filesystem

@bleege
Copy link
Contributor Author

bleege commented Jun 24, 2015

Versions of Static Library dependencies are documented in configure

@bleege bleege removed this from the android-v2.2.0 milestone Oct 28, 2015
@ljbade
Copy link
Contributor

ljbade commented Oct 30, 2015

@incanus Hopefully with Bitrise we can avoid the need to wrap make in gradle.

@ljbade
Copy link
Contributor

ljbade commented Nov 6, 2015

@bleege I think we can close this now we selected Bitrise?

@bleege
Copy link
Contributor Author

bleege commented Nov 6, 2015

I think we can close this now we selected Bitrise?

@ljbade No. This is still need to address the need to have inline debugging of Java and C++. Please see the first sentence in this ticket:

In order to support C++ / NDK debugging in Android Studio

@mdakram
Copy link

mdakram commented Nov 20, 2015

Any update on this ?

@bleege bleege modified the milestones: android-v2.3.0, android-v2.4.0 Dec 4, 2015
@bleege bleege modified the milestones: android-v3.0.0, android-v3.1.0 Dec 21, 2015
@bleege bleege modified the milestones: android-v3.1.0, android-v4.0.0 Jan 20, 2016
@tomlocks
Copy link
Contributor

tomlocks commented Feb 3, 2016

Bumping...

Would It be possible to get at least working Android.mk and Application.mk files with all flags and dependecies needed to build?

@ljbade You mentioned before that you successfully created Android.mk with all dependecies for older SDK version. Can you share it with us?

@bleege
Copy link
Contributor Author

bleege commented Feb 3, 2016

@tomlocks We welcome PRs on enabling this functionality. The difficulty has always been trying to integrate the common C++ code that doesn't live directly in the Android project filesystem as it's reused by iOS, OSX, Qt, and others.

@bleege bleege modified the milestones: android-v4.1.0, android-v4.0.0 Mar 4, 2016
@bleege bleege modified the milestone: android-v4.1.0 Mar 18, 2016
@ghost
Copy link

ghost commented Mar 24, 2016

@bleege How can I import mapbox-gl-native Android sdk project to Android Studio like you? If I use make android command line, it generate .so files, I can't modify C++ files. Thanks!
enter image description here

@bleege
Copy link
Contributor Author

bleege commented Mar 24, 2016

How can I import mapbox-gl-native Android sdk project to Android Studio like you?

@zhangzhuowh The oiginal work on this was focused on copying the C++ source code into the Android Studio jni folder but it was never finalized. This is still the current status of this work if you'd like to pick this effort up. Pull Requests are always welcomed.

@jfirebaugh
Copy link
Contributor

#5855

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

No branches or pull requests

10 participants