Android Studio cannot link against -l1 - android

I have just formatted my computer and reinstalled android studio and sdk & ndk. I've created a new project but now I can't build it with c++ source because I keep getting this error:
.../x86_64-linux-android/bin\ld: error: cannot find -l1
I am not event linking a library called "1". What is it for?

Seems like latest ndk or android-studio has some sort of naming problem or I had a problem when installing it.
I was linking the android library
find_library(ANDROID android)
target_link_library(... ${ANDROID})
but it seems like ${ANDROID} was set to 1. I set it to "android" by hand and now it compiles as expected.

One of the first things the CMake toolchain file does is set(ANDROID TRUE) to indicate that the build is targeting Android. You can't use ANDROID as a variable name in your CMakeLists.txt because it's already used. Best to assume that anything prefixed with ANDROID is part of the implementation.

Related

How to include <glib.h> in android cmake project

I have created an android project on windows with ndk template. I want to include ndk-build project into android studio. This ndk-build project is working fine separately when I run ndk-build command.
My requirement is to convert and use it in android studio so that I can debug the code on android mobile. At this time I am just using share library (so file) and call the required function from adb shell.
I have copied all the source files of my separate ndk project into my android studio project and also added them into native-lib(created by default by android studio) library. But, I am getting an exception on including glib.h.
I am not sure actually how to resolve it.
Please suggest something.
Read this:https://developer.gimp.org/api/2.0/glib/glib-compiling.html
I usually use the following:[To complie]
gcc `pkg-config --cflags --libs glib-2.0 dbus-glib-1` progname.c
Hope this will help you.

Native C Android - Issue in building executable with libptrhead

I'm trying to build an executable from a c file (not written by me) so that I can use it on my phone.
I'm using a toolchain directly from the Android NDK (that use Clang) built for arm64.
The c file needs, as expressed in the makefile, libpthread librtlsdr libmysqlclient, so I downloaded the arm64 versions of these libraries in my toolchain sysroot directory. First question: is this the right way of doing this?
Anyway, after doing this and executing make, it fails saying that it cannot find libpthread.so.0 and libpthread_nonshared.a.
To solve this I copy in the sysroot folder the file it wants from the libc6 arm 64 package (that are not only the two written above, but many others needed in cascade): this way the "make" seems to work fine but once I push it in my device, with the libraries it needs, and run it, I got a runtime error saying:
cannot find verneed/verdef for version index=32770 referenced by symbol "_res" at "/data/local/tmp/TEMP/libc6.so.6"
In this case the problem should be libc6, but I can't figure how to solve this.
This one is related to the libpthread I've downloaded, so the libc6 package, which is probably not suited for Android.
So the real problem is: is there a way to get rid of the first error I mentioned using just the pthread included in Android?
What I hope is that I'm just missing something or using in the wrong way.
Thanks
No, this is not how you are expected to build an executable for Android. You can either use the NDK toolchain, or an alternative toolchain, as described here: Cross compiling static C hello world for Android using arm-linux-gnueabi-gcc.

Android Studio External Native Build Precompiled Headers

I'm porting a project from NDK build to Android Studio.
Currently the project has a precompiled header attached (with NDK build), which speeds up compilation time a lot.
I'm looking for a way to add precompiled header (.pch) to my external native build within Android Studio project. I'm using CMake.
I am in the same situation and I have found several user-made script to do that.
I would recommend this one:
https://github.com/larsch/cmake-precompiled-header
In order to make it work for the latest ndk-tools which uses clang, copy paste the content of this pull request:
https://gist.github.com/leeor/316168500765cf51ae97
into the PrecompiledHeader.cmake file (replace everything in this file, except if you want to keep GCC/ MSVC compatibility, then just you will have to merge the two files which shouldn't be hard).
It should work, except some special CMAKE_CXX_FLAGS that triggers an error in the export_all_flags function, and that I don't know how to fix yet. I'll keep you updated with my progress.

Resolve deprecated NDK warnings in Android Studio

I have an Android app that uses OpenCV's Java wrapper for image processing. To add OpenCV to the project, I had to add the following line to gradle.properties:
android.useDeprecatedNdk=true
This had been working fine without any warnings or errors (that I know of) up until I updated my Android Studio and Gradle after a long time (I'm using Gradle 2.2.2 and Android Studio 2.2.2 now). Now when I build my app, I get the following warnings on the messages window:
Warning:Native C/C++ source code is found, but it seems that NDK
option is not configured. Note that if you have an Android.mk, it is
not used for compilation. The recommended workaround is to remove the
default jni source code directory by adding:
Warning:Deprecated NDK integration enabled by useDeprecatedNdk flag in
gradle.properties will be removed from Android Gradle plugin soon.
Even though the build is successful at this time, as the second warning informs, this is highly likely to cause some trouble in the future, so I want to resolve them as soon as possible before things go sideways.
Does anyone know how to get resolve these warnings? Or are there any other way to import OpenCV to an Android project, other than adding all the compiled code (the .so files) and setting the flag I mentioned earlier? Any help on this will be appreciated.
I would suggest to migrate over to using the native support with cmake. You could check the link which provides a step-by-step tutorial to add OpenCV using cmake via the following link.
You're code should stay the same without any changes, only necessary action is to figure out how to include them within the build process using CMakeLists.txt.
In the project pane, right click your app (in my React Native project it's the "app" catalog), and select "Link C++ project with gradle".
Now you must find the Android.mk file - it should be already generated in your_app/app/build/intermediates/ndk/debug/

How to Build CMake based project for Android/iOS using QtCreator

I have created a Non-Qt C++ (CMake) project using Qt, and I am able to build it using MinGW, MSVC compiler.
So in short, when I am opening my test project I can select the generators under Run CMake Window. I have issue with other platforms.
When I am trying to Add a kit for Android, there are no generators available in the list. I tried the same thing on Macbook, there also the same problem.
I need help on this issue, I couldn't get the proper steps to build the CMake based project for Android/iOS using QtCreator.
P.S. Installed CMake version is 3.2.1 and Qt Version is 5.5, I have installed Android SDK, NDK , and and Java
I would love to tell you "just check this box in the options dialog and it will work", but, unfortunately, there is no generator that you can use to build an Android/iOS project from a CMakeLists.txt file.
I found alternatives, in all cases, I don't think your have a chance to port a whole huge CMake-based project that used to work on Windows (with lots of libraries and 3rd party libraries) work on Android in less than a few days of work....;-)
Personnaly, I wrote a small CMake function generating the .pro file manually from my CMake scripts. It started small but is now huge and it's difficult to share it with you. But, basically, I started from this post on a Qt forum. It creates a simple .pro file that does not work that bad and then you can extend it for your own needs. I like this solution because I have full control on generated .pro file (mine can now build on PC, Android and iOS...but I had a hard time to have this fully work).
Apparently, there's also a way to add a Qt-android CMake support using this open source stuff: https://github.com/LaurentGomila/qt-android-cmake. But I never tried it. You may want to have a look to it. If it works, it may be more convenient that writting your own script generating .pro files. Apparently, it builds an Android apk using androidqtdeploy but without using QtCreator. There's also an iOS support.
Finally, the best may be to have CMake propose a QtCreator "generator" (it would generate .pro files, like CMake generates sln/vcproj files when using Visual Studio generator or makefiles for g++ generator....), but there is no such generator supported. I reported this to CMake team some time ago hoping they could fix that. I understood that there was and would be no plan to do that because CMake targets only "compilers" as "generators" and "QtCreator" is not really a "compiler", it's a "IDE" using external "compilers" to build (MinGW, MSVC, CLang, Android's NDK g++...). It's a shame because CMake known all your project information and could easily generate a .pro file....so, as, CMake is opensource, one may extend CMake with a custom QtCreator file generator...and share it with the whole world,it would be wonderful!
Hope this will help you!

Categories

Resources