2021.04.08

完善ndk使用
This commit is contained in:
FHT
2021-04-08 18:02:16 +08:00
parent b46dcd67d1
commit e9a718484b
11 changed files with 129 additions and 63 deletions

1
.gitignore vendored
View File

@@ -78,3 +78,4 @@ lint/tmp/
/.idea/
/gradlew.bat
/gradlew
/app/.cxx/

View File

@@ -16,7 +16,7 @@ android {
defaultConfig {
applicationId "com.tt.ttutils"
minSdkVersion 16
minSdkVersion 24
targetSdkVersion 30
// versionCode 1
// versionName "1.0"
@@ -26,8 +26,8 @@ android {
ndk {
//选择要添加的对应 cpu 类型的 .so 库。
abiFilters 'armeabi', 'armeabi-v7a', 'arm64-v8a','x86'
// 还可以添加 'x86', 'x86_64', 'mips', 'mips64'
abiFilters 'armeabi-v7a', 'arm64-v8a'
// 还可以添加 'armeabi' , 'x86', 'x86_64', 'mips', 'mips64'
}
manifestPlaceholders = [
JPUSH_PKGNAME: applicationId,
@@ -35,6 +35,12 @@ android {
JPUSH_CHANNEL: "developer-default", //暂时填写默认值即可.
]
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
packagingOptions {
exclude 'META-INF/DEPENDENCIES'
exclude 'META-INF/LICENSE'
@@ -72,7 +78,7 @@ android {
}
}
sourceSets {
beta.res.srcDirs = ['src/beta/res']
beta.res.srcDirs = ['src/beta/res']
}
//签名
@@ -97,6 +103,15 @@ android {
}
buildTypes {
externalNativeBuild {
ndkBuild {
path 'src/main/jni/Android.mk'
}
}
sourceSets.main {
jni.srcDirs = []
jniLibs.srcDirs = ['src/main/jniLibs']
}
debug {
// 显示Log
buildConfigField "boolean", "LOG_DEBUG", "true"
@@ -169,6 +184,9 @@ dependencies {
//Jackson
implementation 'org.codehaus.jackson:jackson-mapper-asl:1.9.13'
implementation 'org.codehaus.jackson:jackson-core-asl:1.9.13'
//view绑定
implementation 'com.jakewharton:butterknife:10.1.0'
annotationProcessor 'com.jakewharton:butterknife-compiler:10.1.0'
//二维码
implementation 'com.google.zxing:core:3.3.0'

View File

@@ -20,14 +20,18 @@
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.MOUNT_UNMOUNT_FILESYSTEMS" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" /> <!-- 华为角标 -->
<uses-permission android:name="com.huawei.android.launcher.permission.CHANGE_BADGE" /> <!-- Optional for location -->
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<!-- 华为角标 -->
<uses-permission android:name="com.huawei.android.launcher.permission.CHANGE_BADGE" />
<!-- Optional for location -->
<uses-permission android:name="android.permission.VIBRATE" />
<uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW" /> <!-- 用于开启 debug 版本的应用在6.0 系统上 层叠窗口权限 -->
<uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW" />
<!-- 用于开启 debug 版本的应用在6.0 系统上 层叠窗口权限 -->
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.CHANGE_WIFI_STATE" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_BACKGROUND_LOCATION" /> <!-- Android Q后台定位权限 -->
<uses-permission android:name="android.permission.ACCESS_BACKGROUND_LOCATION" />
<!-- Android Q后台定位权限 -->
<uses-permission android:name="android.permission.ACCESS_LOCATION_EXTRA_COMMANDS" />
<uses-permission android:name="android.permission.CHANGE_NETWORK_STATE" />
<uses-permission android:name="android.permission.GET_TASKS" />
@@ -41,7 +45,20 @@
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity android:name="com.tt.activity.PackageActivity"></activity>
<activity android:name="com.tt.activity.JMainActivity" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name="com.tt.activity.MainActivity">
<!-- <intent-filter>-->
<!-- <action android:name="android.intent.action.MAIN" />-->
<!-- <category android:name="android.intent.category.LAUNCHER" />-->
<!-- </intent-filter>-->
</activity>
<receiver
android:name="com.tt.receiver.PackageReceiver"
android:enabled="true"
@@ -86,19 +103,15 @@
</intent-filter>
</receiver>
<activity android:name="com.tt.activity.MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity> <!-- -->
<!-- -->
<!-- Rich push 核心功能 since 2.0.6 -->
<activity
android:name="cn.jpush.android.ui.PopWinActivity"
android:exported="false"
android:theme="@style/MyDialogStyle"
tools:replace="android:exported" /> <!-- Required SDK核心功能 -->
tools:replace="android:exported" />
<!-- Required SDK核心功能 -->
<activity
android:name="cn.jpush.android.ui.PushActivity"
android:configChanges="orientation|keyboardHidden"
@@ -111,7 +124,8 @@
<category android:name="android.intent.category.DEFAULT" />
<category android:name="${applicationId}" />
</intent-filter>
</activity> <!-- Required SDK 核心功能 -->
</activity>
<!-- Required SDK 核心功能 -->
<!-- 可配置android:process参数将PushService放在其他进程中 -->
<service
android:name="cn.jpush.android.service.PushService"
@@ -122,12 +136,14 @@
<action android:name="cn.jpush.android.intent.PushService" />
<action android:name="cn.jpush.android.intent.PUSH_TIME" />
</intent-filter>
</service> <!-- since 3.0.9 Required SDK 核心功能 -->
</service>
<!-- since 3.0.9 Required SDK 核心功能 -->
<provider
android:name="cn.jpush.android.service.DataProvider"
android:authorities="${applicationId}.DataProvider"
android:exported="false"
android:process=":pushcore" /> <!-- since 1.8.0 option 可选项。用于同一设备中不同应用的JPush服务相互拉起的功能。 -->
android:process=":pushcore" />
<!-- since 1.8.0 option 可选项。用于同一设备中不同应用的JPush服务相互拉起的功能。 -->
<!-- 若不启用该功能可删除该组件,或把 enabled 设置成 false App 不会被其他 App 拉起,但会拉起其他的 App。 -->
<service
android:name="cn.jpush.android.service.DaemonService"
@@ -138,7 +154,8 @@
<category android:name="${applicationId}" />
</intent-filter>
</service> <!-- 可选如果使用静态Activity方式拉起该组件必须声明 -->
</service>
<!-- 可选如果使用静态Activity方式拉起该组件必须声明 -->
<activity
android:name="cn.jpush.android.service.DActivity"
android:enabled="true"
@@ -150,16 +167,19 @@
<category android:name="${applicationId}" />
</intent-filter>
</activity> <!-- since 3.1.0 Required SDK 核心功能 -->
</activity>
<!-- since 3.1.0 Required SDK 核心功能 -->
<provider
android:name="cn.jpush.android.service.DownloadProvider"
android:authorities="${applicationId}.DownloadProvider"
android:exported="true" /> <!-- Required SDK核心功能 -->
android:exported="true" />
<!-- Required SDK核心功能 -->
<receiver
android:name="cn.jpush.android.service.PushReceiver"
android:enabled="true">
<intent-filter android:priority="1000">
<action android:name="cn.jpush.android.intent.NOTIFICATION_RECEIVED_PROXY" /> <!-- Required 显示通知栏 -->
<action android:name="cn.jpush.android.intent.NOTIFICATION_RECEIVED_PROXY" />
<!-- Required 显示通知栏 -->
<category android:name="${applicationId}" />
</intent-filter>
<intent-filter>
@@ -173,26 +193,36 @@
<data android:scheme="package" />
</intent-filter>
</receiver> <!-- Required SDK核心功能 -->
</receiver>
<!-- Required SDK核心功能 -->
<receiver
android:name="cn.jpush.android.service.AlarmReceiver"
android:exported="false" /> <!-- 3.5.0新增,用于定时展示功能 -->
android:exported="false" />
<!-- 3.5.0新增,用于定时展示功能 -->
<receiver
android:name="cn.jpush.android.service.SchedulerReceiver"
android:exported="false" /> <!-- 3.6.7 新增,用于负反馈组件 -->
<service android:name="cn.jpush.android.service.MessagingIntentService" /> <!-- User defined. For test only 用户自定义的广播接收器 -->
android:exported="false" />
<!-- 3.6.7 新增,用于负反馈组件 -->
<service android:name="cn.jpush.android.service.MessagingIntentService" />
<!-- User defined. For test only 用户自定义的广播接收器 -->
<receiver
android:name="com.tt.sdk.jpush.jpushdemo.MyReceiver"
android:enabled="true">
<intent-filter>
<action android:name="cn.jpush.android.intent.REGISTRATION" /> <!-- Required 用户注册SDK的intent -->
<action android:name="cn.jpush.android.intent.MESSAGE_RECEIVED" /> <!-- Required 用户接收SDK消息的intent -->
<action android:name="cn.jpush.android.intent.NOTIFICATION_RECEIVED" /> <!-- Required 用户接收SDK通知栏信息的intent -->
<action android:name="cn.jpush.android.intent.NOTIFICATION_OPENED" /> <!-- Required 用户打开自定义通知栏的intent -->
<action android:name="cn.jpush.android.intent.CONNECTION" /> <!-- 接收网络变化 连接/断开 since 1.6.3 -->
<action android:name="cn.jpush.android.intent.REGISTRATION" />
<!-- Required 用户注册SDK的intent -->
<action android:name="cn.jpush.android.intent.MESSAGE_RECEIVED" />
<!-- Required 用户接收SDK消息的intent -->
<action android:name="cn.jpush.android.intent.NOTIFICATION_RECEIVED" />
<!-- Required 用户接收SDK通知栏信息的intent -->
<action android:name="cn.jpush.android.intent.NOTIFICATION_OPENED" />
<!-- Required 用户打开自定义通知栏的intent -->
<action android:name="cn.jpush.android.intent.CONNECTION" />
<!-- 接收网络变化 连接/断开 since 1.6.3 -->
<category android:name="${applicationId}" />
</intent-filter>
</receiver> <!-- User defined. For test only 用户自定义接收消息器,3.0.7开始支持,目前新tag/alias接口设置结果会在该广播接收器对应的方法中回调 -->
</receiver>
<!-- User defined. For test only 用户自定义接收消息器,3.0.7开始支持,目前新tag/alias接口设置结果会在该广播接收器对应的方法中回调 -->
<!-- since 3.3.0 接收JPush相关事件 -->
<receiver android:name="com.tt.sdk.jpush.jpushdemo.PushMessageReceiver">
<intent-filter>
@@ -200,7 +230,8 @@
<category android:name="${applicationId}" />
</intent-filter>
</receiver> <!-- since 3.3.0 Required SDK核心功能 -->
</receiver>
<!-- since 3.3.0 Required SDK核心功能 -->
<activity
android:name="cn.jpush.android.service.JNotifyActivity"
android:exported="false"
@@ -212,7 +243,8 @@
<category android:name="${applicationId}" />
</intent-filter>
</activity> <!-- since 3.3.0 Required SDK 核心功能 -->
</activity>
<!-- since 3.3.0 Required SDK 核心功能 -->
<!-- 可配置android:process参数将PushService放在其他进程中 -->
<!-- User defined. For test only 继承自cn.jpush.android.service.JCommonService -->
<service
@@ -221,14 +253,17 @@
<intent-filter>
<action android:name="cn.jiguang.user.service.action" />
</intent-filter>
</service> <!-- since 3.5.6 新增华硕通道 -->
<receiver android:name="cn.jpush.android.asus.AsusPushMessageReceiver" /> <!-- Required . Enable it you can get statistics data with channel -->
</service>
<!-- since 3.5.6 新增华硕通道 -->
<receiver android:name="cn.jpush.android.asus.AsusPushMessageReceiver" />
<!-- Required . Enable it you can get statistics data with channel -->
<meta-data
android:name="JPUSH_CHANNEL"
android:value="${JPUSH_CHANNEL}" />
<meta-data
android:name="JPUSH_APPKEY"
android:value="${JPUSH_APPKEY}" /> <!-- </>值来自开发者平台取得的AppKey -->
android:value="${JPUSH_APPKEY}" />
<!-- </>值来自开发者平台取得的AppKey -->
<meta-data
android:name="design_width_in_dp"
android:value="640" />

View File

@@ -1,13 +1,22 @@
package com.tt.activity;
import android.view.KeyEvent;
import android.widget.TextView;
import android.widget.Toast;
import com.tt.base.BaseActivity;
import com.tt.ttutils.R;
import com.tt.ttutils.java.ToastUtil;
import com.tt.ttutils.jni.NDKTools;
import java.lang.annotation.Native;
import butterknife.BindView;
import butterknife.ButterKnife;
public class JMainActivity extends BaseActivity {
@BindView(R.id.textView)
TextView textView;
@Override
protected int setLayoutResourceID() {
@@ -16,12 +25,13 @@ public class JMainActivity extends BaseActivity {
@Override
protected void initView() {
ButterKnife.bind(this);
}
@Override
protected void initData() {
String ndks = NDKTools.getStringFromNDK();
textView.setText(ndks);
}
// 用来计算返回键的点击间隔时间

View File

@@ -2,7 +2,7 @@ package com.tt.ttutils.jni;
public class NDKTools {
static {
System.loadLibrary("myMeetJni");
System.loadLibrary("NDKTools-jni");
}
public static native String getStringFromNDK();

View File

@@ -0,0 +1,9 @@
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE := NDKTools-jni
LOCAL_SRC_FILES := NDKTools.c
include $(BUILD_SHARED_LIBRARY)

View File

@@ -0,0 +1,13 @@
//
// Created by Administrator on 2021/4/8.
//
#include "com_tt_ttutils_jni_NDKTools.h"
JNIEXPORT jstring JNICALL Java_com_tt_ttutils_jni_NDKTools_getStringFromNDK
//注意!!!这里要与.h文件的一致
(JNIEnv *env, jobject obj) {
return (*env)->NewStringUTF(env, "Hellow WorldNDK");
}

View File

@@ -1,21 +0,0 @@
/* DO NOT EDIT THIS FILE - it is machine generated */
#include <jni.h>
/* Header for class com_tt_ttutils_jni_NDKTools */
#ifndef _Included_com_tt_ttutils_jni_NDKTools
#define _Included_com_tt_ttutils_jni_NDKTools
#ifdef __cplusplus
extern "C" {
#endif
/*
* Class: com_tt_ttutils_jni_NDKTools
* Method: getStringFromNDK
* Signature: ()Ljava/lang/String;
*/
JNIEXPORT jstring JNICALL Java_com_tt_ttutils_jni_NDKTools_getStringFromNDK
(JNIEnv *, jclass);
#ifdef __cplusplus
}
#endif
#endif

2
app/src/main/jni/note.md Normal file
View File

@@ -0,0 +1,2 @@
#https://docs.qq.com/doc/DRE1yeVdvQ21vbm11
#https://www.jianshu.com/p/87ce6f565d37

View File

@@ -1,6 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"