Skip to content

Commit

Permalink
用静态文件替换动态文件,大幅减小aar文件大小
Browse files Browse the repository at this point in the history
  • Loading branch information
devilsen committed Aug 1, 2019
1 parent 5e3a99b commit 2bb6aef
Show file tree
Hide file tree
Showing 22 changed files with 39 additions and 17 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ project.ext {
applicationId = "me.devilsen.czxing"
compileSdkVersion = 28
buildToolsVersion = "29.0.0"
minSdkVersion = 16
minSdkVersion = 21
targetSdkVersion = 28
abortOnLintError = false
checkLintRelease = false
Expand Down
5 changes: 3 additions & 2 deletions czxing/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,13 @@ android {
minSdkVersion rootProject.ext.minSdkVersion
targetSdkVersion rootProject.ext.targetSdkVersion
versionCode 5
versionName "0.4.5"
versionName "0.5"

testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"

externalNativeBuild {
cmake {
cppFlags "-std=c++11 -frtti -fexceptions"
abiFilters "armeabi-v7a","arm64-v8a"
}
}
Expand All @@ -27,7 +28,7 @@ android {
externalNativeBuild {
cmake {
path "src/main/cpp/CMakeLists.txt"
version "3.10.2"
// version "3.10.2"
}
}
compileOptions {
Expand Down
Binary file removed czxing/libs/arm64-v8a/libopencv_java4.so
Binary file not shown.
3 changes: 0 additions & 3 deletions czxing/libs/arm64-v8a/libzxing.so

This file was deleted.

Binary file removed czxing/libs/armeabi-v7a/libopencv_java4.so
Binary file not shown.
3 changes: 0 additions & 3 deletions czxing/libs/armeabi-v7a/libzxing.so

This file was deleted.

Binary file not shown.
Binary file added czxing/opencv/3rdparty/libs/arm64-v8a/libtbb.a
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file added czxing/opencv/3rdparty/libs/armeabi-v7a/libtbb.a
Binary file not shown.
Binary file not shown.
Binary file added czxing/opencv/libs/arm64-v8a/libopencv_core.a
Binary file not shown.
Binary file not shown.
Binary file added czxing/opencv/libs/arm64-v8a/libopencv_imgproc.a
Binary file not shown.
Binary file added czxing/opencv/libs/armeabi-v7a/libopencv_core.a
Binary file not shown.
Binary file not shown.
Binary file not shown.
37 changes: 32 additions & 5 deletions czxing/src/main/cpp/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,51 @@ cmake_minimum_required(VERSION 3.4.1)
#set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${WARNING_FLAGS} -std=c++11 -pthread ")

add_library(
zxing-lib
zxing
SHARED
native-lib.cpp JNIUtils.cpp QRCodeRecognizer.cpp ImageUtil.cpp)

add_subdirectory(zxing)
include_directories(zxing)

include_directories(include)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -L${CMAKE_SOURCE_DIR}/../../../libs/${ANDROID_ABI}")
#set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -L${CMAKE_SOURCE_DIR}/../../../libs/${ANDROID_ABI}")

# 静态方式导入库
add_library(opencv_core STATIC IMPORTED)
add_library(opencv_imgcodecs STATIC IMPORTED)
add_library(opencv_imgproc STATIC IMPORTED)

add_library(cpufeatures STATIC IMPORTED)
add_library(tbb STATIC IMPORTED)
add_library(tegra_hal STATIC IMPORTED)

# 设置库路径
set_target_properties(opencv_core PROPERTIES IMPORTED_LOCATION ${CMAKE_SOURCE_DIR}/../../../opencv/libs/${ANDROID_ABI}/libopencv_core.a)
set_target_properties(opencv_imgcodecs PROPERTIES IMPORTED_LOCATION ${CMAKE_SOURCE_DIR}/../../../opencv/libs/${ANDROID_ABI}/libopencv_imgcodecs.a)
set_target_properties(opencv_imgproc PROPERTIES IMPORTED_LOCATION ${CMAKE_SOURCE_DIR}/../../../opencv/libs/${ANDROID_ABI}/libopencv_imgproc.a)

set_target_properties(cpufeatures PROPERTIES IMPORTED_LOCATION ${CMAKE_SOURCE_DIR}/../../../opencv/3rdparty/libs/${ANDROID_ABI}/libcpufeatures.a)
set_target_properties(tbb PROPERTIES IMPORTED_LOCATION ${CMAKE_SOURCE_DIR}/../../../opencv/3rdparty/libs/${ANDROID_ABI}/libtbb.a)
set_target_properties(tegra_hal PROPERTIES IMPORTED_LOCATION ${CMAKE_SOURCE_DIR}/../../../opencv/3rdparty/libs/${ANDROID_ABI}/libtegra_hal.a)

find_library(
log-lib
log)

target_link_libraries(
zxing-lib
jnigraphics
zxing
ZXingCore
opencv_java4

opencv_imgcodecs
opencv_imgproc
opencv_core

cpufeatures
tbb
tegra_hal

jnigraphics
android
z
${log-lib})
2 changes: 1 addition & 1 deletion czxing/src/main/cpp/JNIUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ bool AnalysisBrightness(JNIEnv *env, const jbyte *bytes, int width, int height)
// 平均亮度
long cameraLight = pixelLightCount / (pixelCount / step);
bool isDarkEnv = false;
LOGE("平均亮度 %ld", cameraLight);
// LOGE("平均亮度 %ld", cameraLight);
// 判断在时间范围 AMBIENT_BRIGHTNESS_WAIT_SCAN_TIME * lightSize 内是不是亮度过暗
if (cameraLight < 60) {
isDarkEnv = true;
Expand Down
2 changes: 1 addition & 1 deletion czxing/src/main/java/me/devilsen/czxing/BarcodeReader.java
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ protected void finalize() throws Throwable {
public static native boolean analysisBrightnessNative(byte[] bytes, int width, int height);

static {
System.loadLibrary("zxing-lib");
System.loadLibrary("zxing");
}

}
2 changes: 1 addition & 1 deletion czxing/src/main/java/me/devilsen/czxing/BarcodeWriter.java
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ private Bitmap write(String text, int width, int height, int color, BarcodeForma
public static native int writeCode(String content, int width, int height, int color, String format, Object[] result);

static {
System.loadLibrary("zxing-lib");
System.loadLibrary("zxing");
}

}

0 comments on commit 2bb6aef

Please sign in to comment.