I am trying to write a program for an executable which is similar to dumpsys. I have created a .cpp file and an Android.mk file. However, when I run ndk-build on either programs, I get compilation error. On the other hand, the same dumpsys program is built correctly when I compile the whole Android source.
The first error I get is
fatal error: utils/Log.h: No such file or directory. Then I have to use LOCAL_C_INCLUDES to solve this.
Next, I get undefined reference to methods errors like undefined reference to android::String16::String16().
After that, I link some objects like String16.o to solve this issue. But some of them depend on other objects and I have to add the one by one. I don't know how Android build compiles dumpsys without facing such issues.
How is ndk-build different from compiling the whole Android source? What is the right way to build if I want to compile a standalone project?
Related
I'm running the latest build of android studio. Trying to make a project compilable and running utilizing the power of this https://github.com/tpruvot/cpuminer-multi/ c++ stuff. What I've tried so far is create new project with c++ support - it creates the corresponding project structure. It also includes CPP file that is called from the main activity. Now let's say I want all this aforementioned miner code to be there as well - I’ve tried just copy-pasting it into the cpp folder. What are my next steps? Calling ndk-build against $ProjectFileDir$\app\src\main directory just fails with an error Android NDK: Your APP_BUILD_SCRIPT points to an unknown file: ./jni/Android.mk . Same goes if I try to import an existing project like https://github.com/mdelling/cpuminer-android - first of all I’m trying to do and ndk-build, but it just fails saying that it treats warning like errors so all the cpp/h functions remain inaccessible and are not packed into resulting apk. If I try to install the resulting apk it just crashed on the start. So for the first case – how can I like all the cpp sources to the app, and for the second – how can I make it work at all?
First of all, the crash is probably because your Java code is trying to load the c++ shared library and fails, because the library was not built due to the NDK errors. So take care of the errors first.
Second, did you configure your Android.mk properly? Have a look here, for example (it is for Eclipse and not Android Studio, but the mk file is the same): Getting started with Android NDK. Looking at an existing simple project can also help: hello-jni.
I've completed the first part of my project, and I want to know how well / bad it performs by profiling it with gprof. I am working on Android using a Linux emulator named Termux, and I am using g++ as the compiler.
Everything compiles without errors and even warnings, and the binary runs perfectly.
So I decided to put the -pg flag among the other flags in my makefile, (meaning that both compilation and linking is performed with -pg) and tried recompiling everything. But something seems to not work properly: during compilation, everything is normal. But when linking I get a argument unused during compilation: '-pg' warning and then a lot of undefined reference to 'mcount' (it doesn't even display all of them, after a bit it says more undefined references to 'mcount' follows) errors, and at the end a linker command failed with exit code 1 error.
What is causing this behaviour? Is something broken / missing on the platform I am using? Can I fix that? How?
Sorry for the short answer, but I'm on mobile. Making a community wiki.
In Termux, g++ is a symlink to clang. -pg is a gnu feature, so does not function when linking using clang.
You could use clang-appropriate techniques for profiling, or install a real g++. One reference is https://android.stackexchange.com/questions/182130/use-gcc-compiler-in-termux but there is also "google performance tools" for profiling out there somewhere.
My goal is to compile amixer from alsa-utils-1.0.29 using Android NDK to an executable I can use on Android device.
I can't find a way to build it using ndk-build nor can I find any documentation on how to achieve this.
Is there a way to accomplish that?
Edit: I tried cross-compiling alsa-lib and alsa-utils on Ubunto using this guide, but result amixer does not run on Android (says no such file or directory).
When I use ndk-build amixer does not compile (keeps complaining on undefined references).
Edit 2:
The steps I did that failed were as following:
- Downloaded alsa-lib and alsa-utils from alsa project site
- Compiled alsa-lib using Android.mk based on this Android.mk - succeeded
- Compiled alsa-utils based on this SO question: alsa-utils + ndk-build not working
- At first I constantly got errors saying there is no rule for building amixer.o. Only replacing $(LOCAL_PATH) with hard-coded path resolved it
- Now, when compiling - although Android.mk points to all required includes, I got lots of undefined reference errors such as: "undefined reference to 'snd_ctl_card_info_sizeof'"
What is the way to build alsa-utils in a way it can be used on Android?
My problem is the following: I have succesfully built GDAL 1.10.1 using an Android toolchain (CC=i686-linux-android-gcc, CXX=i686-linux-android-c++) that produces the following output libraries libgdal.a, libgdal.la, libgdal.lai, libgdal.so, libgdal.so.1, libgdal.so.1.17.1 in the output folder .libs (in the following I'll call this folder $GDAL_LIB_PATH).
I am trying to build a simple Android app (a simple widget application with a QPushButton named TestAndroid) using Qt 5.4 on Windows. If I don't use GDAL everything works fine and I am able to run my app on an Android emulator for all available platforms: x86, armeabi and armeabi-v7.
Nonetheless, if I try to use GDAL (ex. by simply calling GDALAllRegister() in the initialization of the app) and then linking to libgdal.so the application crashes with the following error:
E/art ( 1614):
dlopen("/data/app/org.qtproject.example.TestAndroid-1/lib/x86/libTestAndroid.so",
RTLD_LAZY) failed: dlopen failed: could not load library
"libgdal.so.1" needed by "libTestAndroid.so"; caused by library
"libgdal.so.1" not found
I have verified that the Android platform is the right one (x86), otherwise the linker would skip the wrong libgdal.so object.
I have included libgdal.so in the *.apk (generated by Qt) using ANDROID_EXTRA_LIBS *= $GDAL_LIB_PATH/libgdal.so. The other files libgdal.so.x.x cannot be included in the same way since Qt prevents it.
In order to avoid dynamic linking I have also tried to link my app with libgdal.a but many link-time errors appears (ex. undefined reference to 'atof')
I have searched on the web but I have not found a solution to my problem.
I am not constrained to use dynamic linking so, a solution to any of the following problems is good for me:
Is there a way to avoid the creation of libgdal.so.x.x files when building GDAL ?
Is there a way to include libgdal.so.x.x files in the *.apk file generated by Qt ?
How can I avoid link-time errors when linking the static library libgdal.a ?
Thanks in advance for any reply!
After several days of trials and errors (mainly errors) I have found a solution to my problem.
I'm writing it as an answer to my question so that it may be helpful to others.
The problem was during the link-time of GDAL. Briefly: the linker created the "real name" shared library libgdal.so.1.17.1 together with the links to it libgdal.so.1 and libgdal.so.
For some reasons (which I ignore) forcing the link to libgdal.so, the linker searches for libgdal.so.1 (which, in turn, would have searched for libgdal.so.1.17.1).
The workaround that solved my problem can be summarized in the following steps:
In the GDAL root, run the ./configure according to the desired configuration (see http://trac.osgeo.org/gdal/wiki/BuildingForAndroid) checking that libtool is ENABLED
Edit the created libtool file (e. g. with gedit) as follows:
replace the value of library_names_spec with library_names_spec="\$libname\${shared_ext}"
replace the value of soname_spec with soname_spec=""
Type make
In the output folder .libs/ the only libgdal.so will be created and now the link to libgdal.so seems to work fine.
I can't compile my Android project for the Dalvik VM because of this error:
trouble processing "java/awt/font/NumericShaper.class":Attempt to include a core VM class in
something other than a core library.
It is likely that you have attempted to include the core library from a desktop
virtual machine into an application, which will most assuredly not work. If
you really intend to build a core library -- which is only appropriate as
part of creating a full virtual machine binary, as opposed to compiling an
application -- then use the "--core-library" option to suppress this error
message. If you go ahead and use "--core-library" but are in fact building
an application, then please be aware that your build will still fail at some
point; you will simply be denied the pleasure of reading this helpful error
message.
[2010-03-05 16:33:23 - Notepadv2]1 error; aborting
[2010-03-05 16:33:23 - Notepadv2]Conversion to Dalvik format failed with error 1
I think I somehow messed up my imports but this class never occurs in my imports.
I found the answer to my problem here. It seems that sometimes if you simply use the fix project setup feature from eclipse. Eclipse will drop a second android jar into your source tree. I found a single android.jar and another one under google libraries. I removed one and got rid of the error.
This error is not caused by imports, it is caused by code. Your build either has the source code to java.awt.font.NumericShaper or is attempting to load a JAR that has java.awt.font.NumericShaper. Assuming you did not drop this code into your source tree, check the JARs in your libs/ directory (and, in the case of Eclipse, anything you added to your build path).
I found the solution :
In your project properties, be sure in Java Build Path > Order ans Export that the "android.jar" is unchecked.
Hope that helps,