I'm trying to build pjmedia for Android.
From pjsip library (http://www.pjsip.org/).
I've followed official tutorial (https://trac.pjsip.org/repos/wiki/Getting-Started/Android#OtherAndroidprojects)
1.Created config_site.h with next configuration:
define PJ_CONFIG_ANDROID 1
include <pj/ config_site_sample.h>
2.Specified path to NDK
export ANDROID_NDK_ROOT=/path_to_android_ndk_dir
3.Run android configurations and do make
./configure-android
make dep && make clean && make
I've got builded pjmedia libraries in /pjmedia/lib directory
libpjmedia-arm-unknown-linux-androideabi.a
libpjmedia-audiodev-arm-unknown-linux-androideabi.a
libpjmedia-codec-arm-unknown-linux-androideabi.a
libpjmedia-videodev-arm-unknown-linux-androideabi.a
libpjsdp-arm-unknown-linux-androideabi.a
And questions:
How should I use only pjmedia in Android app?
Where is JNI for pjmedia?
Should I create JNI .cpp wrapper by myself (with SWIG) and build it with pjmedia libraries into single library?
How to generate JNI with SWIG only for pjmedia?
I'm just little bit confused. They give me pjsua example with JNI and library but I don't want pjsua I need pjmedia!
I just don't know how can I use it in Android.
OS: OS X Yosemite
NDK: v9d x86
Help me somebody please! :)
Thanks!
Related
I am trying to create a Flutter application that will be utilizing MethodChannel to call some Java code using dart that will be calling a shared library written in C++.
I was able to compile a Java program that was linked to a C++ library using JNI and run it, However once I tried to import the files into Flutter, I run into errors that the path to the file.so Shared Library could not be found.
I am looking for help regarding how to configure Flutter and its Android files in order to be able to achieve this behaviour.
I will add the CMakeLists.txt I used in order to compile and link the .jar and .so.
CMakeLists.txt
cmake_minimum_required(VERSION 3.7 FATAL_ERROR)
project(shared_library_java_cpp VERSION 1.0.0 LANGUAGES CXX)
set(JAVA_AWT_LIBRARY NotNeeded)
set(JAVA_JVM_LIBRARY NotNeeded)
set(JAVA_INCLUDE_PATH2 NotNeeded)
set(JAVA_AWT_INCLUDE_PATH NotNeeded)
find_package(JNI REQUIRED)
find_package(Java REQUIRED)
include_directories(${JNI_INCLUDE_DIRS})
include(UseJava)
set(CMAKE_CXX_STANDARD 11)
set(CMALE_CXX_STANDARD_REQUIRED ON)
set(JAR_NAME JavaCPP)
set(JAVA_SOURCE_DIRECTORY "/Users/user/Desktop/Temp/com/example/javacpplib")
set(JAVA_SOURCE_FILES ${JAVA_SOURCE_DIRECTORY}/JavaCPP.java)
add_jar(${JAR_NAME} ${JAVA_SOURCE_FILES})
add_library(shared_library_java_cpp SHARED java_cpp.cpp java_cpp.def)
add_executable(java_cpp_exec java_cpp.cpp)
set_target_properties(shared_library_java_cpp PROPERTIES
PUBLIC_HEADER lib_java_cpp.h
VERSION ${PROJECT_VERSION}
SOVERSION 1
OUTPUT_NAME "java_cpp"
XCODE_ATTRIBUTE_CODE_SIGN_IDENTITY "MacOS_ID"
)
In addition to run the code in intelliJ I used this method to load the shared library:
static {
System.load("/Users/user/IdeaProjects/JavaCPP/src/lib_java_cpp.so");
}
I am not sure of what library I should load when running in flutter.
I have found a solution to this problem.
After creating a .jar file and a .so file, I added that .so to the folder android -> app -> src -> main -> jniLibs -> arm64-v8a
I then added this line:
android {
...
sourceSets {
...
main.jniLibs.srcDirs += 'src/main/jniLibs'
}
...
}
to the app/build.gradle file
and I added:
set(JNI_LIBS_DIR ${CMAKE_CURRENT_SOURCE_DIR}/app/src/main/jniLibs/${ANDROID_ABI})
add_library(lib_java_cpp
SHARED
IMPORTED)
set_target_properties(lib_java_cpp
PROPERTIES IMPORTED_LOCATION
${JNI_LIBS_DIR}/lib_java_cpp.so)
...
to the android/CMakeLists.txt file.
finally I called System.loadLibrary("_java_cpp") in MainActivity to load the desired library and to be able to call the Java functions from the jar that use the C++ library. (the lib is added automatically after call to find the correct shared object)
I am stuck at importing a library which is originally written in C++, but has native binding for Java. Here is the library https://github.com/NationalAssociationOfRealtors/libRETS, and I was able to build it through the doc in doc/build, but what after that? I see some makefiles in project/build/ and I want to import this library in Java. Any help will be really appreciated as I cannot find anything in the documentation, all I know is there are some makefiles and the description claims that this library has native bindings for other languages.
Watch the output of ./configure carefully and make sure the build is configured to create the SWIG components (namely, for Java.)
Option summary:
Use ccache .................: no
Use dependency checking ....: no
Use -fPIC...................: yes
Use shared dependencies.....: yes
Compile type................: Normal
Compile examples............: no
Compile SQL compiler........: no
Compile SWIG bindings.......: no <-------- should say yes
With DotNet...............: no
With Java.................: no <--------- me too
With PERL.................: no
With PHP..................: no
With Python 2.............: no
With Python 3.............: no
With Ruby.................: no
With Node.js..............: no
Enable Maintainer Docs......: no
I tried it and a fairly recent version of SWIG was required -- more recent than were in my package manager. Without that, the SWIG bindings don't get built and there's no Java.
However, once you do get that build, it should be a fairly straightforward endeavor of calling into a jar file, as with any other Java project. Who knows, the build might even generate Javadoc for you so you have some idea of what to call.
I have a number of Java libraries that are targeted at being used on both the desktop Java environment and Android Java environment.
I'd like to be able to integrate some sort of Gradle-based lint check in the Java libraries to make sure that I don't use classes/methods unavailable on Android. I've seen that the Android Lint utility can check such things (and output what the minimum Android kit would be to allow it to work).
I know that pulling in the whole Android SDK would work, but it'd be preferable to do it without that on the smaller base libraries that are intended to be shared outside of the Android world.
One reason for this is that I'd like to use Java 8 features that are available through retrolambda but be warned at continuous integration time that I was using an API unavailable in a prior SDK.
Proguard appears to be able to do an effective job of sanity-checking that all classes referenced are present. It does a bunch of other things that I do not need it to do, however it can be configured to do the following:
take an input jar/classpath (the newly compiled Java library)
not require an output jar (no need to save the optimized/obfuscated version)
take a set of input libraries to resolve references
allowing the runtime libraries from Java 7 to be used as a base reference
This allows me to compile using Java 8 features with a reasonable amount of certainty that it should be compatible on Android - either via retrolambda or the new Jack compiler.
Gradle sections to use Proguard for this use:
buildscript {
dependencies {
classpath 'net.sf.proguard:proguard-base:5.2.1'
}
}
task proguardCheck(type: proguard.gradle.ProGuardTask, dependsOn: assemble) {
injars project.jar.archivePath
libraryjars files(System.getenv("JAVA7_HOME") + "/jre/lib/rt.jar")
libraryjars files(System.getenv("JAVA7_HOME") + "/jre/lib/jce.jar")
libraryjars files(configurations.compile)
// Don't really try to do anything, we just want this tool for it's bytecode lint
dontshrink
dontobfuscate
dontoptimize
// Don't fail if LambdaMetafactory is missing - it would be handled by Retrolambda / Jack
dontwarn 'java.lang.invoke.LambdaMetafactory'
}
A strong guarantee of compatibility would be to reference the android.jar for the given minimum-compatible version of Android to be targetted. However without pulling in the Andorid SDK, Java 6 is a good target for really old Android and Java 7 for Android SDK >= 4.4 (although NIO 2.0 is missing and probably other APIs as well).
This is a completely newbie question from a Java programmer trying to learn Erlang. What's the equivalent of a Java JAR file in Erlang by which 3'rd party libraries can be included in an Erlang application?
The other day I made a copy of the mochijson2.erl in my project and it worked, but I am wondering if there's a better/more formal way of discovering and including libraries in the Erlang world.
If you're familiar with Maven (or its siblings), the Erlang analogue is Rebar.
You could create a rebar.config (similar to a POM file) with the contents
{deps, [
{mochiweb, "2.9.0", {git, "https://github.com/mochi/mochiweb.git", {tag, "v2.9.0"}}}
]}.
Then rebar get-deps && rebar compile will fetch mochiweb (and any dependencies it declares), build the dependencies, and build your own code.
A little background:
I have a java application that needs to talk to a third party hardware on mac. They have given me the sdk but it is not in Java. So I am trying to make jnilib that will act as a bridge between my java application and the SDK.
The issue:
I have made a small sample jnilib that talks to the SDK but when I try to use it in my java program I get the following error
Exception in thread "main" java.lang.UnsatisfiedLinkError: /Users/john.doe/Desktop/eclipse/workspace/Lesson13_Jni_Smart7/bin/libSmartTest7.jnilib: Library not loaded: build/Release/SMARTResponseSDK.framework/Versions/A/SMARTResponseSDK Referenced from: /Users/john.doe/Desktop/eclipse/workspace/Lesson13_Jni_Smart7/bin/libSmartTest7.jnilib
Reason: image not found
at java.lang.ClassLoader$NativeLibrary.load(Native Method)
at java.lang.ClassLoader.loadLibrary0(ClassLoader.java:1827)
at java.lang.ClassLoader.loadLibrary(ClassLoader.java:1742)
at java.lang.Runtime.loadLibrary0(Runtime.java:823)
at java.lang.System.loadLibrary(System.java:1045)
at com.learning.lesson13.JniSmart7.<clinit>(JniSmart7.java:6)
From the error it looks like my libSmartTest7.jnilib is looking for the library SMARTResponseSDK.
What I have tried
I know where the library SMARTResponseSDK is on my Mac. I tried copying it over to my working folder in eclipse but I still get the error. I have tried using the -DJava.library.path but I still get the error.
Any ideas on what the best possible approach would be.
Once you are inside JNI code, it no longer matters what java.library.path points at.
Once you are inside JNI code, all you can do is to make sure library is visible to your code via LD_LIBRARY_PATH/DYLD_LIBRARY_PATH, or you can dynamically load your library file from any location you like.
So, for you, I suggest to take a look here:
dynamic loading of library in JNI - http://jnicookbook.owsiak.org/recipe-No-018/
Calling code from shared library (adapter pattern) - http://jnicookbook.owsiak.org/recipe-No-023/
You can also benefit from compilation flags while building your JNI library and use rpath.