How to integrate Foxit PDF Reader in Android? - android

I have followed these steps in order to compile the Foxit library:
1) Download and install the Eclipse IDE (http://www.eclipse.org/), the Android SDK, ADT plugin for Eclipse, and the Android NDK (http://developer.android.com/sdk/index.html).
a) For Windows use, also download and install Cygwin (http://www.cygwin.com/). During Cygwin setup, make sure to include the “Devel -> make” package.
2) Download the Foxit embedded SDK Package.
3) Extract the Foxit embedded SDK Package to any directory.
4) Place the Foxit embedded SDK library and header files in fpdfemb_android/examples/demos/bin and include directory.
5) Build the NDK layer.
a) Open the Android.mk makefile in fpdfemb_android/examples/demos/demo(like “demo_view”)/jni/ in a text editor and fill in the Foxit library name in the area designated for LOCAL_LDLIBS, dropping the lib prefix:
The demo is shipped as:
LOCAL_LDLIBS +=../bin/# fill in library name here
To add downloaded libfoxit.a from step 2, fill in as:
LOCAL_LDLIBS :=../bin/libfoxit.a
If the library provide is not named “libfoxit.a” please adjust accordingly.
b) Open Cygwin (Windows), or a terminal (Linux based), and navigate to the fpdfemb_android/examples/demos/demo(like “demo_view”) directory. Run “ndk-build –B” to build the NDK/JNI layer.
Example:
me#myStation /myProjectPath/ > ndk-build –B
This assumes that the ndk directory is part of the $PATH environment variable. The command can also be qualified with the path to the NDK directory.
But then I'm getting this error in the terminal:
Android NDK: WARNING:jni/Android.mk:fpdfembedsdk: non-system libraries in linker flags: jni/../../bin/libfoxit.a
Android NDK: This is likely to result in incorrect builds. Try using LOCAL_STATIC_LIBRARIES
Android NDK: or LOCAL_SHARED_LIBRARIES instead to list the library dependencies of the
Android NDK: current module
make: * No rule to make target `–B'. Stop.
Could you please tell me if there is any way to resolve this?
Thank you.

I recommend trying Foxit's new MobilePDF SDK for Android which will provide most of the functionality found in the embedded PDF SDK that you've previously tried but it includes a user interface and can be integrated into your Android projects quickly.
http://www.foxitsdk.com/products/mobile-pdf-sdk/
This SDK replaces Foxit's embedded SDK.

Related

How to integrate CLSTM library in Android application?

I'm working on a project that requires me to integrate CLSTM library (a C++ implementation of LSTM networks for OCR) in an Android application. I'm a beginner Android developer and this is my first time working with NDK.
I'm having trouble integrating the C++ code with my project. I have been trying to do it for a couple of days, but have still gotten nowhere. I have been looking for solutions everywhere, but I can't find exact instructions for my problem.
What I have been able to do till now is:
Created new project with C++ support
Downloaded Android NDK
Downloaded CMake
Created JNI Folder
Cloned the source code into JNI Folder
I am not sure if I was supposed to do steps 4, 5 above. Also, from all the tutorials I have found, I think after these I am supposed to create an Android.mk and Application.mk files. I'm not sure what to write in them.
Can anyone guide me with exact steps for how to integrate this particular library in my Android application?
It's not really clear what exact problem you are having but I'll give it a shot as I've been dabbling with this myself recently. These are the steps I took:
Using classpath 'com.android.tools.build:gradle:2.2.0 as my build tools version
Added the C libraries in my app/src/main/jni directory
Added an Android.mk and Application.mk file in my app/src/main/jni directory
Added the following to my app/build.gradle:
```
externalNativeBuild {
ndkBuild {
path 'src/main/jni/Android.mk'
}
}
```
You can find the contents of my Application.mk and Android.mk here.
I based my setup of the .mk files & contents upon the keepassdroid project.
Edit:
if you also want to use travis-ci you can use this to download and use the android ndk in your builds:
before_install:
- curl -L http://dl.google.com/android/repository/android-ndk-r14-linux-x86_64.zip -O
- unzip -q android-ndk-r14-linux-x86_64.zip
- export ANDROID_NDK_HOME=`pwd`/android-ndk-r14
- export PATH=$PATH:${ANDROID_NDK_HOME}

How to build host static library with Android NDK?

I'm trying to build android adb tool from the sources. Since file Android.mk is presented i'm running ndk-build tool to build it. But unfortunately i'm having following errors:
/Users/user/Documents/dev/tmp/adb/jni/Android.mk:95: /softdev/android-ndk-r10c/build/core/build-host-static-library.mk: No such file or directory
/Users/user/Documents/dev/tmp/adb/jni/Android.mk:183: /softdev/android-ndk-r10c/build/core/build-host-executable.mk: No such file or directory
Android NDK: Trying to define local module 'adbd' in /Users/user/Documents/dev/tmp/adb/jni/Android.mk.
Android NDK: But this module was already defined by /Users/user/Documents/dev/tmp/adb/jni/Android.mk.
/softdev/android-ndk-r10c/build/core/build-module.mk:34: *** Android NDK: Aborting. . Stop.
I've checked files (build-host-*-*.mk) are absent for some reason. I've found them in someone's git repo, but it's for windows. After copying build-host-*-*.mk to my local ndk folder i'm getting another errors:
Android NDK: /Users/user/Documents/dev/tmp/adb/jni/Android.mk:adb: Unknown LOCAL_MODULE_CLASS value: HOST_STATIC_LIBRARY
/softdev/android-ndk-r10c/build/core/build-module.mk:29: *** Android NDK: Aborting . Stop.
So it seems that just copying that files is not enough. How can i make it built?
adb is a host tool (which runs on your PC rather than on the Android device), and NDK has no support for building host executables. It does provide some stubs but the feature was never fully implemented.
The git repo you are linking to is not the official NDK r7b but a patched version with host target support added. This includes a bit more than just a single file – see the full diff here.
You will need to apply this patch (or copy all the scripts which were modified) to your local NDK setup. If you are running an NDK version other than r7b, you may have to make some additional modifications.
See also my question, in which I basically ran into the same issue.

Compile libpcap using Android NDK

I've been doing a lot of attempts to get libpcap compiled for Android, and I don't see any pattern or any progress worth writing down.
I have a very simple sniffer (that works fine in a MIPS linux) that uses libpcap, so I thought to myself oh, ok... no biggie... I'll just compile libpcap for Android (in the end, Android is just a Linux)... and here's where the problems started. I have no idea on how to compile libpcap using ndk-build and the Android.mk and all that infrastructure.
I have the Android NDK in a directory. That NDK has the toolchains built (I have a lot of directories under ~/Documents/Projects/Android_NDK/toolchains/ ) but none of the toolchains has libpcap available.
I've tried with two different libpcap version or... branches:
The Android one, which is the one I'd like to use,
https://android.googlesource.com/platform/external/libpcap/
and the regular one:
http://www.tcpdump.org/release/libpcap-1.5.3.tar.gz
All tries I've done have been very unsuccessful. I've seen the question Android NDK: Link using a pre-compiled static library which is similar, but I'm still getting various errors.
I have downloaded those pcap libraries to their own directories. Maybe is that the problem? Do I need to put the Android libpcap in some directory within the NDK root directory and re-create the toolchains?
I'm using NDK-r9 on a MacOSX 10.9.2 64bit.
Finally!!
After getting annoyed by the non existing headers in and stuff like that, I found this question, that pointed to a SVN repo (http://sourceforge.net/p/prueba-android/code/HEAD/tree/trunk/jni/) with a libpcap that compiled!
If someone else wants additional details on how my Android.mk and directory structure looks like, please add a comment and I'll extend this answer.
Please read an excellent article at http://blog.umitproject.org/2011/05/libpcap-for-android.html. There are instructions that will help you link to libpcap, but the most important takeaway is that you cannot use libpcap on non-rooted Android. So maybe it's not worth your effort.
On a rooted device, you can simply install a free sniffer like Shark for Root.
If anyone else is having problems compiling libpcap for Android using the NDK, there is version 1.5.2 here with a built Android.mk file in it: https://android.googlesource.com/platform/external/libpcap.git and instructions for compiling this using the NDK are here: http://ducbh.blogspot.co.uk/2013/12/cross-compile-libpcap-for-android.html . I can confirm this works using the current NDK (r10b)...although you may have to add AndroidManifest.xml (blank) and and Application.mk that points to your Android.mk file.
I don't think it would be that difficult to modify the .mk file for the current libpcap version (1.6.2)
In case anyone ends up here in 2022+. You can now cross-compile for Android from the official source. Steps:
First, setup the NDK:
Download Android NDK (I used r21e) and extract to a directory of your choosing:
$ cd ~
$ mkdir Android
$ unzip android-ndk-r21e-linux-x86_64.zip
Prepare the environment variables for cross-compilation by placing the commands below (replace <YOUR_USER>) into a file named setup_env.sh (can be saved anywhere):
export NDK=/home/<YOUR_USER>/Android/android-ndk-r21e
export TOOLCHAIN=$NDK/toolchains/llvm/prebuilt/linux-x86_64
export TARGET=aarch64-linux-android
export API=21
export AR=$TOOLCHAIN/bin/$TARGET-ar
export AS=$TOOLCHAIN/bin/$TARGET-as
export CC=$TOOLCHAIN/bin/$TARGET$API-clang
export CXX=$TOOLCHAIN/bin/$TARGET$API-clang++
export LD=$TOOLCHAIN/bin/$TARGET-ld
export RANLIB=$TOOLCHAIN/bin/$TARGET-ranlib
export STRIP=$TOOLCHAIN/bin/$TARGET-strip
Now, build libpcap:
Download libpcap tar ball (e.g. https://www.tcpdump.org/release/libpcap-1.10.1.tar.gz)
Extract (in a directory of your choosing): tar xf libpcap-1.10.1.tar.gz
Prepare your env: source <path_to>/setup_env.sh
Change into the extract libpcap directory and configure: ./configure --host=aarch64-linux-android
I found the Makefile generated had the wrong linker set (line 48), so I had to change it to: LD = /home/<YOUR_USER>/Android/android-ndk-r21e/toolchains/llvm/prebuilt/linux-x86_64/x86_64-linux-android/bin/ld
Finally, build: make
This build worked for me with running tcpreplay on a rooted Android, hopefully it works for other purposes as well!

Using ARMv7 and ARM library in the same Android App

I am struggling with using Dropbox (Sync API) and Andengine in the same android app. Both are using native libraries and, as far as I know, Andengine is developed for ARMv7a and Dropbox for ARM systems. Running each part of the application on its own, everything works fine. However, combining both parts results in a: java.lang.UnsatisfiedLinkError: Couldn't load DropboxSync: findLibrary returned null.
It seems that only the armeabi-v7a folder is checked for the library as soon as this folder is present? However, the libDropboxSync.so is only located in the armeabi folder.
Everything is tested with a Nexus S running Android 4.1.2.
Thanks in advance,
Stefan
From $NDK/docs/CPU-ARCH-ABIS.html: if primary-abi is found secondary won't be scanned.
III.3. Automatic extraction of native code at install time:
-----------------------------------------------------------
When installing an application, the package manager service will scan
the .apk and look for any shared library of the form:
lib/<primary-abi>/lib<name>.so
If one is found, then it is copied under $APPDIR/lib/lib<name>.so,
where $APPDIR corresponds to the application's specific data directory.
If none is found, and a secondary ABI is defined, the service will
then scan for shared libraries of the form:
You can check this by;
$ adb shell getprop|grep abi
[ro.product.cpu.abi2]: [armeabi]
[ro.product.cpu.abi]: [armeabi-v7a]
as you can see primary abi is more specific then the secondary one.
Solution-wise you can move armv5 library under armv7-a. It should work, but it will be only visible to such devices under Google Play.
Check out the 3rd and 4th point
Within Android Studio, switch to the "project view".
From the libs directory in the downloaded SDK, drag dropbox-sync-sdk-android.jar into your project's app/libs directory.
Right-click on dropbox-sync-sdk-android.jar and choose "Add as library". Click "OK" on the dialog that appears.
Make a new directory in your project under app/src/main called jniLibs. From the SDK, drag armeabi, armeabi-v7a, mips, and x86 into
the new jniLibs directory.

Android.mk rules to make a file.o from many files.txt then link it with other files.o produced from files.cpp

I'm porting a modem connection manager written in C++ from linux to gingerbread. This does not end up being an "app" with a "gui" that I would use a java wrapper with the NDK but a service that is called at boot from "init.rc". I found some not up to date docs related to android build system under build/core/. There you find some html files explaining the basics of Android build system and several "file.mk" which are some templates for common situation like creating a c++ executable, static libraries, shared library etc.
I place my tree with all the sources under external/myservice and it's meant to be compiled at the same time as Android itself. (I've already ported the kernel to my platform and it works, just the modem left to go)
In a subfolder in an Android.mk file, I have a bunch of ".cpp" files listed with the variable LOCAL_SRC_FILES := cppfile1.cpp cppfile2.cpp .... That will generate cppfile1.o cppfile2.o ...
I need to link those cppfile*.o with objfile.o to form a libfile.so. I found the rules on how to generate a libfile.so from a bunch of files.o.
Where things get complicated, is to port the "linux makefile" command to create objfile.o. Here is how it looks like
$(LD) $(LDFLAGS) -r -b binary -o QMIDB.o \
QMI/Entity.txt \
QMI/EnumEntry.txt \
QMI/Enum.txt \
QMI/Field.txt \
QMI/Struct.txt
Which means it is a linker job to merge a bunch of text file to make that objfile.o. That file is just a bunch of initialized data structure, there is no code to execute in it but it's pretty ugly to look at all files.txt with a text editor.
I have no clue how to integrate that in the Android.mk file. How can it be done? I'd even appreciate just a hint on where I can find more information. It is easy to find information on building Android applications but it's another story to find anything closer to Android/Kernel itself.
From the mk. file file you can easily get so file....
You need to use android Ndk setup and cygwin setup if you are using windows platform to genreate so file from your native code.
Firstly install and place ndk to a location...
Then install cygwin setup not default one check all features in the installation process (it a sort of linux terminal) as ndk-build command is recognized from linux terminal.
Now from your cygwin terminal get access to your project folder jni file.. or where mk is placed...
http://developer.android.com/sdk/ndk/index.html
Use the following referal how to run ndk-build command from cygwin terminal..
Now providing complete path of ndk we use the ndk-build command...
After that the complied code generates the .so file for our project...
Now what we are using System.loadlibrary command to use the so file i.e our native code can now be used.
Note to get so file form mk we need to complie using ndk setup.We can't directly copy paste so file to make our native code run.Also we we are using windows platfrom we will need to use cygwin setup to do that

Categories

Resources