-
Notifications
You must be signed in to change notification settings - Fork 263
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
cannot locate symbol "rand" on pre-Android 5.0 devices #844
Comments
If you rebuild libabc.so passing Probably, you did not set ANDROID_PLATFORM correctly in your build.gradle. The best way is to set You should expect to see |
Hi, Alex @alexcohn I use standalone toolchain to build libabc.so, and use it in AS with gradle/cmake. I think the problem is with the configuration of the standalone toolchain or the parameters passed to cmake when building libabc.so, but not related to the -DANDROID_PLATFORM setting in build.gradle. I use the following command to generate the toolchain and call the cmake command:
|
@neevek with standalone toolchain rules of the game are entirely different. You must supply the appropriate standalone toolchain up-front. It will ignore ANDROID_PLATFORM altogether, and in CFLAGS especally. The problem is that CMake does not work well with latest NDK releases, see for example #623. NDK installs its 'private' CMake toolchain file (I am sorry about the inevitable confusion between the CMake toolchain, NDK standalone toolchain, and the Clang toolchain in NDK). Personally, I believe that the best way is to let Android Studio build your native libraries, and tune your CMakeLists.txt to comply with the NDK way of defining the things. This path will allow easy upgrades when NDK r19, r20, and on are released. If you cannot afford such change, then you should stay with an NDK version that is supported by 'official' CMake Cross Compiling for Android with a Standalone Toolchain. This depends on your version of CMake, and is not well documented. I believe that r15 is OK, but your mileage may vary. Please understand that it is not impossible to tweak your build scripts so that you can use NDK r18. But this is a lot of nitpicking work which will inevitably need redoing when NDK r19 is released. |
Thanks @alexcohn, it's good to know such issues with standalone toolchain. I can't afford to make big changes to the build procedure at the moment, I will just leave pre-5.0 users behind, and move all my native code to Android Studio later when I have time. |
In theory the quick and dirty fix is just to pass the correct API level to What is |
Hi @DanAlbert Yes, now I use the standalone toolchain created with |
@DanAlbert I am afraid it's worse than you believe. In theory, results of |
😱 Hadn't seen that bug before. Yeah, that complicates things quite a bit. Is removing your use of the standalone toolchain an option? They're unnecessary with CMake. Any idea what version CMake is choosing to build for? If you check the |
@DanAlbert OK, I will try it without standalone toolchain.
|
Looks like that did at least compile for 19. Check the link command just in case, but that looks right to me. |
Hi @DanAlbert
The included subproject failed to find necessary libraries. With standalone toolchain, there's no such issue. The question is what configuration should I adjust to make the subproject find the libraries? I also notice that there are no header files (no |
I recommend to use standalone toolchain to build x264 and ffmpeg. Well, for the latter I know the magic enchantmnet that works with NDK r18 and does not require preparing standalone toolchain, but there is no guarantee that some other version of ffmpeg or NDK will work without modifications. But IMO there is very little gain in calling such library build from your CMake script. I would recommend to build the ffmpage libraries (including libx264) once (for all supported ABIs, which means up to 4 sets of binaries), and use the prebuilt libraries in your project. Simpy launchin make to verify that ffmpeg build is up-to-date has been taking too long in my experience. So, I usually prepare the standalone toolchains for the minimal API Livel supported by my app, build all third-party dependencies, like ffmpeg, and keep the binaries as large files in my git repo. Once in a while, when a new release happens to be desireable enough, I build a new set of binaries, run all compatibility tests, and when (and if) all subtle incompatibilities of the new version are resolved, push the next set of binaries to the repo. My collegues and I use these prebuilt binaries when we compile our project (many times a day), using the integrated externalNativeBuild of Android Studio. This practice saves us a lot of time and makes on-boarding of new team members less painful. |
Yes, that's what Unified Headers are about. |
That's what I did. I use standalone toolchain to build ffmpeg, x264 and my own library code into a single shared library, and reference it in my gradle project, but it doesn't work as expected hence this issue. I wrote a small script to check if ffmpeg and x264 are built, if the |
Until r19, yes. In r19 everything is in sysroot.
This corner of CMake is open ended enough that there's no way I'm going to be able to guess at what went wrong. I'll need more details (preferably a repro case) to do anything about that.
Wait, what are you using cmake for then? Do you just want |
Does that mean there will be no android-platforms? everything in NDK is unified, so standalone toolchain is also unnecessary in that case?
More than that, I usually need to write some wrapper code and JNI code around the referenced libraries, so |
Correct. #780 |
The code compiles and runs fine on Android 5.0 and above, but crashes on pre-5.0 devices, I tried 4.0.4 and 4.4, I tried setting ANDROID_PLATFORM=android-19, but it didn't work. The error message is as below:
The text was updated successfully, but these errors were encountered: