【问题标题】:Could not resolve all files for configuration ':app:debugRuntimeClasspath' because could not find TensorFlow Lite files无法解析配置“:app:debugRuntimeClasspath”的所有文件,因为找不到 TensorFlow Lite 文件
【发布时间】:2022-01-02 20:37:14
【问题描述】:

我尝试使用 nightly tensorflow lite 构建一个 TensorFlow lite 应用程序。

但是,它发生了八个相同的错误,如以下错误。 我想寻找这个问题的解决方案,但是我在任何地方都找不到(当然,也可能只是我找不到)。

FAILURE: Build completed with 8 failures.

1: Task failed with an exception.
-----------
* What went wrong:
Execution failed for task ':app:checkDebugAarMetadata'.
> Could not resolve all files for configuration ':app:debugRuntimeClasspath'.
   > 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)
    }
}

【问题讨论】:

    标签: java android tensorflow gradle tensorflow-lite


    【解决方案1】:

    解决方案

    我已经解决了这个问题。

    1。评论一行

    首先,您应该在 build.gradle (app)

    中注释以下行 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'
    }
    

    之后

    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 代码有一个 <activity> </activity> 对并且它包含一个 <intent-filter> </intent-filter> 对,那么您应该添加一行 android:exported = true

    之前

    <activity android:name="com.example.android.tflitecamerademo.CameraActivity"
              android:screenOrientation="portrait"
              android:label="@string/app_name">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
    

    之后

    <activity android:name="com.example.android.tflitecamerademo.CameraActivity"
              android:screenOrientation="portrait"
              android:label="@string/app_name"
              android:exported="true">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-10-01
      • 1970-01-01
      • 1970-01-01
      • 2021-12-03
      • 1970-01-01
      • 1970-01-01
      • 2019-07-07
      • 2021-12-04
      相关资源
      最近更新 更多