1. 程式人生 > >Android Studio “import org.tensorflow.lite.Interpreter” cannot resolve symbol "tensorflow"

Android Studio “import org.tensorflow.lite.Interpreter” cannot resolve symbol "tensorflow"

我要用到的是tensorflow-lite,但是編譯器找不到。

  • 解決方法1:

開啟File->Project Structure->app->Dependencies,點選右上角加號,如圖:

點選第一個,得到如下圖所示。在這裡檢索tensorflow的庫。我們這裡要新增的是“org.tensorflow:tensorflow-lite:+”,有可能在這裡檢索不到。如果檢索不到,就參考解決方法2。

  • 解決方法2

直接到工程的build.gradle中,在
dependencies {
    implementation fileTree(include: ['*.jar'], dir: 'libs')
    implementation 'com.android.support:appcompat-v7:28.0.0'
    implementation 'com.android.support.constraint:constraint-layout:1.1.3'
    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'
}
新增
implementation 'org.tensorflow:tensorflow-lite:+'

其實解決方法2中的檔案與解決方法1中的設定是同步的,但是可能存在一些bug,導致有些庫只能通過方法2新增。