1.File --> New Moudle
2.添加文件结构
image.png
3.库的build.gradle配置
plugins {
id 'com.android.library'
}
android {
namespace 'com.wireless.yolov5ncnn'
compileSdk 33
defaultConfig {
minSdk 24
targetSdk 33
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'
ndk {
abiFilters "armeabi-v7a","arm64-v8a"
}
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
externalNativeBuild {
cmake {
path file('src/main/cpp/CMakeLists.txt')
version '3.22.1'
}
}
}
dependencies {
implementation 'androidx.appcompat:appcompat:1.6.1'
implementation 'com.google.android.material:material:1.8.0'
testImplementation 'junit:junit:4.13.2'
androidTestImplementation 'androidx.test.ext:junit:1.1.5'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.5.1'
}
task makeJar(type: Copy) {
delete 'libs/yolov5ncnn.jar' //删除之前的旧jar包
from('build/intermediates/aar_main_jar/release/') //这里是你要打包成jar的代码
into('libs/') //将jar包输出到指定目录下 (我这里也不成功)
include('classes.jar')
rename('classes.jar', 'yolov5ncnn.jar') //自定义jar包的名字(这里我rename并不成功!)
}
makeJar.dependsOn(build)
4.执行build.gradle的makeJar任务
5.使用依赖app下的build.gradle 增加
打包文件目录
image.png
dependencies {
implementation(fileTree("libs"))
}
混淆文件增加这个配置,防止打包编译功能不生效
image.png
网友评论