parent
fc4a2d405f
commit
daf865b400
13 changed files with 206 additions and 3 deletions
@ -0,0 +1 @@ |
||||
/build |
@ -0,0 +1,47 @@ |
||||
plugins { |
||||
id 'com.android.library' |
||||
} |
||||
|
||||
android { |
||||
namespace 'com.kingoit.survey.security' |
||||
compileSdk 32 |
||||
|
||||
defaultConfig { |
||||
minSdk 21 |
||||
targetSdk 32 |
||||
|
||||
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" |
||||
consumerProguardFiles "consumer-rules.pro" |
||||
externalNativeBuild { |
||||
cmake { |
||||
cppFlags "" |
||||
} |
||||
} |
||||
} |
||||
|
||||
buildTypes { |
||||
release { |
||||
minifyEnabled false |
||||
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' |
||||
} |
||||
} |
||||
externalNativeBuild { |
||||
cmake { |
||||
path "src/main/cpp/CMakeLists.txt" |
||||
version "3.18.1" |
||||
} |
||||
} |
||||
compileOptions { |
||||
sourceCompatibility JavaVersion.VERSION_1_8 |
||||
targetCompatibility JavaVersion.VERSION_1_8 |
||||
} |
||||
} |
||||
|
||||
dependencies { |
||||
|
||||
implementation 'androidx.appcompat:appcompat:1.5.1' |
||||
implementation 'com.google.android.material:material:1.6.1' |
||||
testImplementation 'junit:junit:4.13.2' |
||||
androidTestImplementation 'androidx.test.ext:junit:1.1.3' |
||||
androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0' |
||||
} |
@ -0,0 +1,21 @@ |
||||
# Add project specific ProGuard rules here. |
||||
# You can control the set of applied configuration files using the |
||||
# proguardFiles setting in build.gradle. |
||||
# |
||||
# For more details, see |
||||
# http://developer.android.com/guide/developing/tools/proguard.html |
||||
|
||||
# If your project uses WebView with JS, uncomment the following |
||||
# and specify the fully qualified class name to the JavaScript interface |
||||
# class: |
||||
#-keepclassmembers class fqcn.of.javascript.interface.for.webview { |
||||
# public *; |
||||
#} |
||||
|
||||
# Uncomment this to preserve the line number information for |
||||
# debugging stack traces. |
||||
#-keepattributes SourceFile,LineNumberTable |
||||
|
||||
# If you keep the line number information, uncomment this to |
||||
# hide the original source file name. |
||||
#-renamesourcefileattribute SourceFile |
@ -0,0 +1,26 @@ |
||||
package com.kingoit.survey.security; |
||||
|
||||
import android.content.Context; |
||||
|
||||
import androidx.test.platform.app.InstrumentationRegistry; |
||||
import androidx.test.ext.junit.runners.AndroidJUnit4; |
||||
|
||||
import org.junit.Test; |
||||
import org.junit.runner.RunWith; |
||||
|
||||
import static org.junit.Assert.*; |
||||
|
||||
/** |
||||
* Instrumented test, which will execute on an Android device. |
||||
* |
||||
* @see <a href="http://d.android.com/tools/testing">Testing documentation</a> |
||||
*/ |
||||
@RunWith(AndroidJUnit4.class) |
||||
public class ExampleInstrumentedTest { |
||||
@Test |
||||
public void useAppContext() { |
||||
// Context of the app under test.
|
||||
Context appContext = InstrumentationRegistry.getInstrumentation().getTargetContext(); |
||||
assertEquals("com.kingoit.survey.security.test", appContext.getPackageName()); |
||||
} |
||||
} |
@ -0,0 +1,4 @@ |
||||
<?xml version="1.0" encoding="utf-8"?> |
||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android"> |
||||
|
||||
</manifest> |
@ -0,0 +1,48 @@ |
||||
# For more information about using CMake with Android Studio, read the |
||||
# documentation: https://d.android.com/studio/projects/add-native-code.html |
||||
|
||||
# Sets the minimum version of CMake required to build the native library. |
||||
|
||||
cmake_minimum_required(VERSION 3.18.1) |
||||
|
||||
# Declares and names the project. |
||||
|
||||
project("security") |
||||
|
||||
# Creates and names a library, sets it as either STATIC |
||||
# or SHARED, and provides the relative paths to its source code. |
||||
# You can define multiple libraries, and CMake builds them for you. |
||||
# Gradle automatically packages shared libraries with your APK. |
||||
|
||||
add_library( # Sets the name of the library. |
||||
security |
||||
|
||||
# Sets the library as a shared library. |
||||
SHARED |
||||
|
||||
# Provides a relative path to your source file(s). |
||||
security.cpp) |
||||
|
||||
# Searches for a specified prebuilt library and stores the path as a |
||||
# variable. Because CMake includes system libraries in the search path by |
||||
# default, you only need to specify the name of the public NDK library |
||||
# you want to add. CMake verifies that the library exists before |
||||
# completing its build. |
||||
|
||||
find_library( # Sets the name of the path variable. |
||||
log-lib |
||||
|
||||
# Specifies the name of the NDK library that |
||||
# you want CMake to locate. |
||||
log) |
||||
|
||||
# Specifies libraries CMake should link to your target library. You |
||||
# can link multiple libraries, such as libraries you define in this |
||||
# build script, prebuilt third-party libraries, or system libraries. |
||||
|
||||
target_link_libraries( # Specifies the target library. |
||||
security |
||||
|
||||
# Links the target library to the log library |
||||
# included in the NDK. |
||||
${log-lib}) |
@ -0,0 +1,23 @@ |
||||
#include <jni.h> |
||||
#include <string> |
||||
|
||||
#define PROVIDER AndroidKeyStore |
||||
|
||||
extern "C" JNIEXPORT void JNICALL |
||||
Java_com_kingoit_survey_security_JNIBridge_init( |
||||
JNIEnv* env, |
||||
jobject /* this */) { |
||||
|
||||
|
||||
jclass keyStore_cls = env->FindClass("java/security/KeyStore");//获得ArrayList类引用
|
||||
jmethodID getInstance = env->GetStaticMethodID(keyStore_cls,"getInstance","(Ljava/lang/String;)Ljava/security/KeyStore;"); |
||||
jobject keyStore = env->CallStaticObjectMethod(keyStore_cls,getInstance,env->NewStringUTF("AndroidKeyStore")); |
||||
|
||||
|
||||
|
||||
jclass keyPairGenerator_cls = env->FindClass("java/security/KeyPairGenerator");//获得ArrayList类引用
|
||||
jmethodID getInstanceKeyPairGenerator = env->GetStaticMethodID(keyPairGenerator_cls,"getInstance","(Ljava/lang/String;Ljava/lang/String;)Ljava/security/KeyPairGenerator;"); |
||||
jobject keyPairGenerator = env->CallStaticObjectMethod(keyPairGenerator_cls,getInstanceKeyPairGenerator,env->NewStringUTF("RSA"),env->NewStringUTF("AndroidKeyStore")); |
||||
|
||||
|
||||
} |
@ -0,0 +1,13 @@ |
||||
package com.kingoit.survey.security; |
||||
|
||||
public class JNIBridge { |
||||
|
||||
static { |
||||
System.loadLibrary("security"); |
||||
} |
||||
|
||||
/** |
||||
* |
||||
*/ |
||||
public native void init(); |
||||
} |
@ -0,0 +1,17 @@ |
||||
package com.kingoit.survey.security; |
||||
|
||||
import org.junit.Test; |
||||
|
||||
import static org.junit.Assert.*; |
||||
|
||||
/** |
||||
* Example local unit test, which will execute on the development machine (host). |
||||
* |
||||
* @see <a href="http://d.android.com/tools/testing">Testing documentation</a> |
||||
*/ |
||||
public class ExampleUnitTest { |
||||
@Test |
||||
public void addition_isCorrect() { |
||||
assertEquals(4, 2 + 2); |
||||
} |
||||
} |
Loading…
Reference in new issue