Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 75d1bc8

Browse files
Merge pull request #9 from pramonow/sample_jni
Added sample for jni kotlin
2 parents c6a8356 + 7b8036c commit 75d1bc8

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

45 files changed

+909
-0
lines changed

‎JniSample/.gitignore

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
*.iml
2+
.gradle
3+
/local.properties
4+
/.idea/caches/build_file_checksums.ser
5+
/.idea/libraries
6+
/.idea/modules.xml
7+
/.idea/workspace.xml
8+
.DS_Store
9+
/build
10+
/captures
11+
.externalNativeBuild

‎JniSample/.idea/codeStyles/Project.xml

Lines changed: 35 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎JniSample/.idea/codeStyles/codeStyleConfig.xml

Lines changed: 5 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎JniSample/.idea/gradle.xml

Lines changed: 18 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎JniSample/.idea/misc.xml

Lines changed: 38 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎JniSample/.idea/runConfigurations.xml

Lines changed: 12 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎JniSample/.idea/vcs.xml

Lines changed: 6 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎JniSample/README.md

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
# Jni android sample
2+
3+
JNI stands for Java Native Interface. This sample is showing how to call native c/c++ method to be used inside android.
4+
In order to run this sample, you need to install <b>NDK</b> in android SDK manager beforehand.
5+
6+
If you looked through, the project contains c/c++ file which contains:
7+
8+
#include <jni.h>
9+
#include "sample-jni.h"
10+
11+
12+
extern "C"
13+
JNIEXPORT jint JNICALL
14+
15+
Java_com_pramonow_androidadvanced_JniActivity_getKey(JNIEnv* pEnv, jobject instance, jint key1) {
16+
return key1+200;
17+
}
18+
19+
And the getKey function will be able to be called inside the activity:
20+
21+
//Our Jni method
22+
external fun getKey(key:Int):Int
23+
24+
companion object {
25+
init {
26+
System.loadLibrary("sample-jni")
27+
}
28+
}
29+
30+
override fun onCreate(savedInstanceState: Bundle?) {
31+
super.onCreate(savedInstanceState)
32+
setContentView(R.layout.activity_jni)
33+
34+
Toast.makeText(this,getKey(55).toString(),Toast.LENGTH_SHORT).show() // will show 255
35+
}

‎JniSample/app/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/build

‎JniSample/app/CMakeLists.txt

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
# Sets the minimum version of CMake required to build your native library.
2+
# This ensures that a certain set of CMake features is available to
3+
# your build.
4+
5+
cmake_minimum_required(VERSION 3.10.2)
6+
7+
# Specifies a library name, specifies whether the library is STATIC or
8+
# SHARED, and provides relative paths to the source code. You can
9+
# define multiple libraries by adding multiple add_library() commands,
10+
# and CMake builds them for you. When you build your app, Gradle
11+
# automatically packages shared libraries with your APK.
12+
13+
add_library( # Specifies the name of the library.
14+
sample-jni
15+
16+
# Sets the library as a shared library.
17+
SHARED
18+
19+
# Provides a relative path to your source file(s).
20+
src/main/cpp/sample-jni.cpp )
21+
22+
# Searches for a specified prebuilt library and stores the path as a
23+
# variable. Because CMake includes system libraries in the search path by
24+
# default, you only need to specify the name of the public NDK library
25+
# you want to add. CMake verifies that the library exists before
26+
# completing its build.
27+
28+
find_library( # Sets the name of the path variable.
29+
log-lib
30+
31+
# Specifies the name of the NDK library that
32+
# you want CMake to locate.
33+
log )
34+
35+
# Specifies libraries CMake should link to your target library. You
36+
# can link multiple libraries, such as libraries you define in this
37+
# build script, prebuilt third-party libraries, or system libraries.
38+
39+
target_link_libraries( # Specifies the target library.
40+
sample-jni
41+
42+
# Links the target library to the log library
43+
# included in the NDK.
44+
${log-lib} )

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /