#java #android #tensorflow #gradle #tensorflow-lite
Вопрос:
Я попытался создать приложение TensorFlow lite с nightly tensorflow lite
помощью .
Тем не менее, произошло восемь идентичных ошибок, таких как следующая ошибка. Я хотел найти решение этой проблемы, но я нигде не мог ее найти (конечно, может быть, я просто не мог ее найти).
FAILURE: Build completed with 8 failures. 1: Task failed with an exception. ----------- * What went wrong: Execution failed for task ':app:checkDebugAarMetadata'. gt; Could not resolve all files for configuration ':app:debugRuntimeClasspath'. gt; Could not find org.tensorflow:tensorflow-lite-local:0.0.0. Searched in the following locations: - file:/Users/JJ/.m2/repository/org/tensorflow/tensorflow-lite-local/0.0.0/tensorflow-lite-local-0.0.0.pom - https://repo.maven.apache.org/maven2/org/tensorflow/tensorflow-lite-local/0.0.0/tensorflow-lite-local-0.0.0.pom - https://dl.google.com/dl/android/maven2/org/tensorflow/tensorflow-lite-local/0.0.0/tensorflow-lite-local-0.0.0.pom - http://oss.sonatype.org/content/repositories/snapshots/org/tensorflow/tensorflow-lite-local/0.0.0/tensorflow-lite-local-0.0.0.pom Required by: project :app * Try: Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.
И, это мое build.gradle (Project)
.
// Top-level build file where you can add configuration options common to all sub-projects/modules. buildscript { repositories { mavenCentral() google() } dependencies { classpath 'com.android.tools.build:gradle:7.0.3' // NOTE: Do not place your application dependencies here; they belong // in the individual module build.gradle files } } allprojects { repositories { mavenLocal() mavenCentral() google() maven { // Only for snapshot artifacts name 'ossrh-snapshot' url 'http://oss.sonatype.org/content/repositories/snapshots' allowInsecureProtocol = true } } } task clean(type: Delete) { delete rootProject.buildDir }
К тому же, это мое build.gradle (App)
.
apply plugin: 'com.android.application' android { compileSdkVersion 31 buildToolsVersion "30.0.3" defaultConfig { applicationId "android.example.com.tflitecamerademo" // Required by Camera2 API. minSdkVersion 21 targetSdkVersion 31 versionCode 1 versionName "1.0" } lintOptions { abortOnError false } buildTypes { release { minifyEnabled false proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' } } aaptOptions { noCompress "tflite" } compileOptions { sourceCompatibility JavaVersion.VERSION_1_8 targetCompatibility JavaVersion.VERSION_1_8 } } repositories { mavenCentral() maven { // Only for snapshot artifacts name 'ossrh-snapshot' url 'http://oss.sonatype.org/content/repositories/snapshots' allowInsecureProtocol = true } } allprojects { repositories { // Uncomment if you want to use a local repo. // mavenLocal() mavenCentral() maven { // Only for snapshot artifacts name 'ossrh-snapshot' url 'http://oss.sonatype.org/content/repositories/snapshots' allowInsecureProtocol = true } } } dependencies { implementation fileTree(dir: 'libs', include: ['*.jar']) implementation 'androidx.appcompat:appcompat:1.4.0' implementation 'androidx.constraintlayout:constraintlayout:2.1.2' implementation 'com.google.android.material:material:1.4.0' implementation 'androidx.annotation:annotation:1.3.0' implementation 'androidx.legacy:legacy-support-v13:1.0.0' // Build off of nightly TensorFlow Lite implementation 'org.tensorflow:tensorflow-lite:0.0.0-nightly-SNAPSHOT' implementation 'org.tensorflow:tensorflow-lite-gpu:0.0.0-nightly-SNAPSHOT' // Use local TensorFlow library implementation 'org.tensorflow:tensorflow-lite-local:0.0.0' } def targetFolder = "src/main/assets" def modelFloatDownloadUrl = "https://storage.googleapis.com/download.tensorflow.org/models/mobilenet_v1_2018_02_22/mobilenet_v1_1.0_224.tgz" def modelQuantDownloadUrl = "https://storage.googleapis.com/download.tensorflow.org/models/mobilenet_v1_2018_08_02/mobilenet_v1_1.0_224_quant.tgz" def localCacheFloat = "build/intermediates/mobilenet_v1_1.0_224.tgz" def localCacheQuant = "build/intermediates/mmobilenet_v1_1.0_224_quant.tgz" task downloadModelFloat(type: DownloadUrlTask) { doFirst { println "Downloading ${modelFloatDownloadUrl}" } sourceUrl = "${modelFloatDownloadUrl}" target = file("${localCacheFloat}") } task downloadModelQuant(type: DownloadUrlTask) { doFirst { println "Downloading ${modelQuantDownloadUrl}" } sourceUrl = "${modelQuantDownloadUrl}" target = file("${localCacheQuant}") } task unzipModelFloat(type: Copy, dependsOn: 'downloadModelFloat') { doFirst { println "Unzipping ${localCacheFloat}" } from tarTree("${localCacheFloat}") into "${targetFolder}" } task unzipModelQuant(type: Copy, dependsOn: 'downloadModelQuant') { doFirst { println "Unzipping ${localCacheQuant}" } from tarTree("${localCacheQuant}") into "${targetFolder}" } task cleanUnusedFiles(type: Delete, dependsOn: ['unzipModelFloat', 'unzipModelQuant']) { delete fileTree("${targetFolder}").matching { include "*.pb" include "*.ckpt.*" include "*.pbtxt.*" include "*.quant_info.*" include "*.meta" } } // Ensure the model file is downloaded and extracted before every build preBuild.dependsOn unzipModelFloat preBuild.dependsOn unzipModelQuant preBuild.dependsOn cleanUnusedFiles class DownloadUrlTask extends DefaultTask { @Input String sourceUrl @OutputFile File target @TaskAction void download() { ant.get(src: sourceUrl, dest: target) } }
Ответ №1:
Решение
Я решил эту проблему.
1. Прокомментируйте строку
Прежде всего, вы должны прокомментировать следующую строку implementation 'org.tensorflow:tensorflow-lite-local:0.0.0'
в build.gradle (приложение)
До
dependencies { implementation fileTree(dir: 'libs', include: ['*.jar']) implementation 'androidx.appcompat:appcompat:1.4.0' implementation 'androidx.constraintlayout:constraintlayout:2.1.2' implementation 'com.google.android.material:material:1.4.0' implementation 'androidx.annotation:annotation:1.3.0' implementation 'androidx.legacy:legacy-support-v13:1.0.0' // Build off of nightly TensorFlow Lite implementation 'org.tensorflow:tensorflow-lite:0.0.0-nightly-SNAPSHOT' implementation 'org.tensorflow:tensorflow-lite-gpu:0.0.0-nightly-SNAPSHOT' // Use local TensorFlow library implementation 'org.tensorflow:tensorflow-lite-local:0.0.0' }
После
dependencies { implementation fileTree(dir: 'libs', include: ['*.jar']) implementation 'androidx.appcompat:appcompat:1.4.0' implementation 'androidx.constraintlayout:constraintlayout:2.1.2' implementation 'com.google.android.material:material:1.4.0' implementation 'androidx.annotation:annotation:1.3.0' implementation 'androidx.legacy:legacy-support-v13:1.0.0' // Build off of nightly TensorFlow Lite implementation 'org.tensorflow:tensorflow-lite:0.0.0-nightly-SNAPSHOT' implementation 'org.tensorflow:tensorflow-lite-gpu:0.0.0-nightly-SNAPSHOT' // Use local TensorFlow library // implementation 'org.tensorflow:tensorflow-lite-local:0.0.0' }
2. Добавление строки в AndroidManifest.xml
Если ваш AndroidManifest.xml код имеет lt;activitygt; lt;/activitygt;
пару и включает в себя lt;intent-filtergt; lt;/intent-filtergt;
пару, затем вы должны добавить строку android:exported = true
.
До
lt;activity android:name="com.example.android.tflitecamerademo.CameraActivity" android:screenOrientation="portrait" android:label="@string/app_name"gt; lt;intent-filtergt; lt;action android:name="android.intent.action.MAIN" /gt; lt;category android:name="android.intent.category.LAUNCHER" /gt; lt;/intent-filtergt; lt;/activitygt;
После
lt;activity android:name="com.example.android.tflitecamerademo.CameraActivity" android:screenOrientation="portrait" android:label="@string/app_name" android:exported="true"gt; lt;intent-filtergt; lt;action android:name="android.intent.action.MAIN" /gt; lt;category android:name="android.intent.category.LAUNCHER" /gt; lt;/intent-filtergt; lt;/activitygt;