From 7ceb082077e5e96ae97f43fce3862f67c5a86959 Mon Sep 17 00:00:00 2001
From: DefTruth <31974251+DefTruth@users.noreply.github.com>
Date: Mon, 21 Nov 2022 15:22:28 +0800
Subject: [PATCH] [Android] add fastdeploy android sdk download task (#646)
* [Bug Fix] fix android app detail page errors
* [Android] fix realtime camera mode and shutter
* [Bug Fix] fix AllocateSegmentationResultFromJava error
* [Bug Fix] fix camera preview size setting problem
* [Model] use uint8 buffer instead of fp32 in ppseg postprocess
* [Model] revert changes in ppseg
* [Model] revert postprocess changes in ppseg
* [Android] add fastdeploy android sdk download task
---
java/android/app/build.gradle | 77 +++++++++++++++----
.../app/src/main/res/values/strings.xml | 2 +-
java/android/fastdeploy/build.gradle | 18 +++--
3 files changed, 72 insertions(+), 25 deletions(-)
diff --git a/java/android/app/build.gradle b/java/android/app/build.gradle
index d106ff18a..0e2b5f326 100644
--- a/java/android/app/build.gradle
+++ b/java/android/app/build.gradle
@@ -25,33 +25,39 @@ android {
}
dependencies {
- implementation fileTree(include: ['*.jar'], dir: 'libs')
+ implementation fileTree(include: ['*.aar'], dir: 'libs')
implementation 'com.android.support:appcompat-v7:28.0.0'
//noinspection GradleDependency
implementation 'com.android.support.constraint:constraint-layout:1.1.3'
implementation 'com.android.support:design:28.0.0'
implementation 'org.jetbrains:annotations:15.0'
- implementation project(path: ':fastdeploy')
//noinspection GradleDependency
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
}
-def archives = [
+def FD_MODEL = [
[
- 'src': 'https://bj.bcebos.com/paddlehub/fastdeploy/picodet_s_320_coco_lcnet.tgz',
- 'dest' : 'src/main/assets/models'
+ 'src' : 'https://bj.bcebos.com/paddlehub/fastdeploy/picodet_s_320_coco_lcnet.tgz',
+ 'dest': 'src/main/assets/models'
],
[
- 'src': 'https://bj.bcebos.com/paddlehub/fastdeploy/picodet_l_320_coco_lcnet.tgz',
- 'dest' : 'src/main/assets/models'
+ 'src' : 'https://bj.bcebos.com/paddlehub/fastdeploy/picodet_l_320_coco_lcnet.tgz',
+ 'dest': 'src/main/assets/models'
]
]
-task downloadAndExtractArchives(type: DefaultTask) {
+def FD_JAVA_SDK = [
+ [
+ 'src' : 'https://bj.bcebos.com/fastdeploy/test/fastdeploy-android-sdk-latest-dev.aar',
+ 'dest': 'libs'
+ ]
+]
+
+task downloadAndExtractModels(type: DefaultTask) {
doFirst {
- println "Downloading and extracting archives including models ..."
+ println "Downloading and extracting fastdeploy models ..."
}
doLast {
// Prepare cache folder for archives
@@ -59,24 +65,63 @@ task downloadAndExtractArchives(type: DefaultTask) {
if (!file("${cachePath}").exists()) {
mkdir "${cachePath}"
}
- archives.eachWithIndex { archive, index ->
+ FD_MODEL.eachWithIndex { model, index ->
MessageDigest messageDigest = MessageDigest.getInstance('MD5')
- messageDigest.update(archive.src.bytes)
+ messageDigest.update(model.src.bytes)
String cacheName = new BigInteger(1, messageDigest.digest()).toString(32)
// Download the target archive if not exists
- boolean copyFiles = !file("${archive.dest}").exists()
+ boolean copyFiles = !file("${model.dest}").exists()
if (!file("${cachePath}/${cacheName}.tgz").exists()) {
- ant.get(src: archive.src, dest: file("${cachePath}/${cacheName}.tgz"))
- copyFiles = true // force to copy files from the latest archive files
+ println "Downloading ${model.src} -> ${cachePath}/${cacheName}.tgz"
+ ant.get(src: model.src, dest: file("${cachePath}/${cacheName}.tgz"))
+ copyFiles = true
+ // force to copy files from the latest archive files
}
// Extract the target archive if its dest path does not exists
if (copyFiles) {
+ println "Coping ${cachePath}/${cacheName}.aar -> ${model.dest}"
copy {
from tarTree("${cachePath}/${cacheName}.tgz")
- into "${archive.dest}"
+ into "${model.dest}"
}
}
}
}
}
-preBuild.dependsOn downloadAndExtractArchives
\ No newline at end of file
+
+task downloadAndExtractSDKs(type: DefaultTask) {
+ doFirst {
+ println "Downloading and extracting fastdeploy android java sdk ..."
+ }
+ doLast {
+ // Prepare cache folder for archives
+ String cachePath = "cache"
+ if (!file("${cachePath}").exists()) {
+ mkdir "${cachePath}"
+ }
+ FD_JAVA_SDK.eachWithIndex { sdk, index ->
+ String[] sdkPaths = sdk.src.split("/")
+ // e.g fastdeploy-android-sdk-latest-dev.aar
+ String sdkName = sdkPaths[sdkPaths.length - 1]
+ // Download the target SDK if not exists
+ boolean copyFiles = !file("${sdk.dest}/${sdkName}").exists()
+ if (!file("${cachePath}/${sdkName}").exists()) {
+ println "Downloading ${sdk.src} -> ${cachePath}/${sdkName}"
+ ant.get(src: sdk.src, dest: file("${cachePath}/${sdkName}"))
+ copyFiles = true
+ // force to copy files from the latest downloaded sdk
+ }
+ // Copy the target archive if its dest path does not exists
+ if (copyFiles) {
+ println "Coping ${cachePath}/${sdkName} -> ${sdk.dest}/${sdkName}"
+ copy {
+ from "${cachePath}/${sdkName}"
+ into "${sdk.dest}"
+ }
+ }
+ }
+ }
+}
+
+preBuild.dependsOn downloadAndExtractSDKs
+preBuild.dependsOn downloadAndExtractModels
\ No newline at end of file
diff --git a/java/android/app/src/main/res/values/strings.xml b/java/android/app/src/main/res/values/strings.xml
index 267871056..b5c396f5f 100644
--- a/java/android/app/src/main/res/values/strings.xml
+++ b/java/android/app/src/main/res/values/strings.xml
@@ -35,7 +35,7 @@
models/scrfd_500m_bnkps_shape320x320_pd
- models/portrait_pp_humansegv2_lite_256x144_inference_model
+ models/human_pp_humansegv1_lite_192x192_inference_model
拍照识别
实时识别
diff --git a/java/android/fastdeploy/build.gradle b/java/android/fastdeploy/build.gradle
index b83ccee54..a7bc3f67e 100644
--- a/java/android/fastdeploy/build.gradle
+++ b/java/android/fastdeploy/build.gradle
@@ -44,7 +44,7 @@ dependencies {
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
}
-def archives = [
+def FD_CXX_LIB = [
[
'src' : 'https://bj.bcebos.com/fastdeploy/test/fastdeploy-android-latest-shared-dev.tgz',
'dest': 'libs'
@@ -53,7 +53,7 @@ def archives = [
task downloadAndExtractLibs(type: DefaultTask) {
doFirst {
- println "Downloading and extracting archives including libs ..."
+ println "Downloading and extracting fastdeploy android c++ lib ..."
}
doLast {
// Prepare cache folder for archives
@@ -61,24 +61,26 @@ task downloadAndExtractLibs(type: DefaultTask) {
if (!file("${cachePath}").exists()) {
mkdir "${cachePath}"
}
- archives.eachWithIndex { archive, index ->
+ FD_CXX_LIB.eachWithIndex { lib, index ->
MessageDigest messageDigest = MessageDigest.getInstance('MD5')
- messageDigest.update(archive.src.bytes)
+ messageDigest.update(lib.src.bytes)
String cacheName = new BigInteger(1, messageDigest.digest()).toString(32)
// Download the target archive if not exists
- boolean copyFiles = !file("${archive.dest}").exists()
+ boolean copyFiles = !file("${lib.dest}").exists()
if (!file("${cachePath}/${cacheName}.tgz").exists()) {
- ant.get(src: archive.src, dest: file("${cachePath}/${cacheName}.tgz"))
- copyFiles = true // force to copy files from the latest archive files
+ ant.get(src: lib.src, dest: file("${cachePath}/${cacheName}.tgz"))
+ copyFiles = true
+ // force to copy files from the latest archive files
}
// Extract the target archive if its dest path does not exists
if (copyFiles) {
copy {
from tarTree("${cachePath}/${cacheName}.tgz")
- into "${archive.dest}"
+ into "${lib.dest}"
}
}
}
}
}
+
preBuild.dependsOn downloadAndExtractLibs
\ No newline at end of file