How to compile c code in Android project without header-file? - android

I have a library with c code, and I want to compile it to a .so lib with NDK, but when I run ndk-build command, it needs header file and there is no header file in that library, only dot c.
There are so many source files, and how can I achieve this with it?
Is there a way to compile it without header-file?
Or maybe generate them in batches?
Thanks

You cannot compile a c/cpp file without having access to the header files it requires. Some default header files are usually provided by the corresponding stdlibc which ships with the compiler you use. Others you have to provide yourself by installing their libraries in appropriate paths or giving their path explicitly during compilation.
Generally header files are included by the pre-processor, prior to compilation, as they provide some functionality which is required by the code within the c file (except when they are pointless includes).

Related

Best way to distribute Android Library

What is the best way to distribute android Library. I dont want the user to see my code, library has images and layout xml. Here is my understanding. Please correct if I am wrong.
If I make Jar then I cannot add res folder as part of my jar. (I know using progurad is an option to obfuscate code.)
If I publish aar I have to make my repo public?
So my question is that how can I distribute my library to user without giving access to my code while adding images and layout files as part of that library.
There is aar format which was exactly created for libraries distribution.
Use Jar
U may have to get the image file and res files through a constructor if that is null use default
Actually you can't, even if it's a jar there is a tons of tools to reverse engineer it (one of the tools)
The only thing you can do is obfuscated your code so it turns to unreadable code. Read here about proGuard with android(proGuard)
For the distribution part with res I recommend using gradle. For example Jake Wharton has a library named butterknife.
He distributed it using gradle so the user could just add
compile 'com.jakewharton:butterknife:6.1.0'
in his gradle files and be good to go.
Another example with res files distrbuted in gradle is the android support libs which can be grabbed by adding:
compile "com.android.support:support-v4:18.0.+"

External librairy inside Air native extension for Android

[RESOLVED]
Finally the problem was that my external lib use external jars. And the content of thoses jars also have to be in the extension jar. For example:
extension.jar have ton contain all the compiled classes of:
externallib.jar
externallib_referencing_external_lib.jar
[/RESOLVED]
First, I've been looking throught this topics
AIR 3 Native Extensions for Android - Can I/How to include 3rd party libraries?
How to include additional Jar in Android Native Extension for Adobe Air Mobile
I got a similar problem. But not exactly the same. And the solution didn't worked for me :(.
First of all, I don't have any visible error.
-I can easily talk between java and action script.
-The gateway is set without problems.
My problem comes when, from my java-side-part of the extension, I try to call a 3rd party library. This library is (and I think this is where I do something wrong) linked to my project as an external lib, in .jar format.
So when I make a call to 3rd party library, it just doesn't print anything. Neither on the adobe part or on the java part. The logs that are before my call are printed but not the ones after.
I tried different solutions that are:
-Taking all compiled class files of my external lib and add it inside the main native extension jar [link1]
same result (no errors)
-including the 3rd party jar inside the ANE by adding a dependence file that require the .jar [link2]
with this method i got this error that I don't get
aapt tool failed:ERROR: input directory '--auto-add-overlay' does not exist
My third party library also include's itself some external .jars so do I need to include every jars inside the same packaged jar?
I can see that a lot of people are dealing with issues like that so my question would be:
What is the best way to include 3rd party library inside android AIR Native Extension ?.
For information, here is what I do to create the ANE
adt -package -target ane AirInfinitGameANE\AirInfinitGame.ane AirInfinitGameASLib\src\extension.xml -swc AirInfinitGameANE\AirInfinitGameASLib.swc -platform Android-ARM -C AirInfinitGameLib .
AirInfinitGameASLib: just the folder with the actionScript part and the config xml file
AirInfinitGameANE: folder in the one that will be the native extension
AirInfinitGameLib: the eclipse java project. I need to put in that folder the airInfinitgamelib.jar(extension jar) and the library.swf (from the swc file) in order to beeing able to compile the ANE.
Here it is ! Thanks a lot for thoses who'll read me.

Make a library that is statically linked

So , I have installed Ubuntu(but still use the Android kernel) on my Android phone with the intention of using it to compile native code for the device using the glibc.
I made a library, which I plan to use it in an app which I want to make, using JNI, but I am using the math library. My question is:
Is there a way to include these libraries into the library that I
created so that my phone can use the glibc library instead of the
bionic(which is what the NDK uses) library?
NOTE: I have tried making a test program that uses the library and statically links to make sure that the compiled code would work on the android OS and not just Ubuntu, and I came to the conclusion that it does :) So any answer pertaining to my question would be a great help.
You can use ar to extract the original .o files from any .a files:
ar x libm.a
You can then select whichever .o files you like and link them into your own code.
.a library files can be viewed as tar files with extra symbol-index features (although I don't know how similar the internals are).
WARNING: in general, you can only use .o files from static libraries in your main application. If you try to link them into a shared library (.so file) you may be out of luck. The .o file needs to have been created with -fPIC for that to work, and this is often not the case for static libraries.

Building/finding shared libraries from Android source code

I wish to back port the Android RTP APIs introduced in version 3.1(Honeycomb) to earlier versions. I downloaded the source of version 4.0 and found that it these APIs had both java and native code. In order to build the native code with the NDK, certain shared libraries are required.
According the Android.mk file, these are libnativehelper, libcutils, libutils, and libmedia. Though the source of all of these are present in the source code, building them was difficult. Each required many other shared libraries. For eg, libmedia requires these shared libraries: libui, libcutils, libutils, libbinder, libsonivox, libicuuc, libexpat, libcamera_client, libstagefright_foundation, libgui and libdl.
So my question is, is there some way of obtaining the original 4 shared libs? Does it involve building the entire source?
Say I need to build a piece of native code which is going to use standard Android shared libraries such as libutils, libcutlis, libmedia. I would perform following steps:
Install AOSP repository with target version.
Add my source code to appropriate directories under ./frameworks/base. In your case it might be easier to create a separate folder and put proper Android.mk of course.
You might get compile errors if required functions from those standard shared libraries are not present in the previous version.
When you build the code as part of AOSP it will build required libraries and link them for you automatically.
P.S. To accomplish that you're better to use a Linux-based build host.
using cygwin terminal, build native part i.e. jni folder. To build using cygwin, goto jni folder using cygdrive command. Then type ndk-build. After successful completion, shared libraries i.e. .so files will be created in libs folder.
I can understand your problem, you can pull the libraries from /system/lib of device or emulator. But you need a system permission. But you can do it by installing application.
Otherwise build your source code on linux platfor. Building process is very easy, just using 2 or 3 command. First time it is needed long time to build. After that you need very short time to build, it will build only according to the timestamp of modified code.
Please have a look here

Problem loading pre-built library via Android NDK

I am attempting to add a third-party library to my Android app. It utilizes a .jar file and a .so file. This is a pre-built .so file (i.e. not built specifically for the Android app) - which I know will provide me with plenty of problems down the road. I do NOT have access to the source files for the .jar or .so files!
I am attempting to dynamically load the library via a call to System.loadLibrary("foo");. Currently, when attempting to run the app, it crashes with the UnsatisfiedLinkError: Library foo not found. I have the .so file in both the libs/ and the libs/armeabi file in my project.
Am I chasing after a ghost here? I am trying to determine if what I'm after is even feasible. I have no native code that I'm referencing - all my function calls are to the .jar file that is, as I understand it, backed by the .so file. I have not run the Android.mk file as I'm not compiling anything - the .so file is already provided. I could really use some advice as to what direction to proceed from here.
It's possible that the base name given to System.loadLibrary() is expanding to a file (or path) name different than that of the actual prebuilt library. Logcat should show you exactly what it is trying to load. You could also use System.load() with a full path/file name instead of System.loadLibrary() - though you really should get it working with the later.
While I think it would generate a different error message, it's also possible that the .so is not android compatible - it must not only be for a compatible processor type and abi, but not depend on any dynamic libraries (such as a non-bionic libc) not installed on the device.

Categories

Resources