From b129b24304d1af5c08b2f3df2f22ad1a74d40708 Mon Sep 17 00:00:00 2001 From: wuhongsheng <664116298@qq.com> Date: Tue, 17 May 2022 12:22:54 +0800 Subject: [PATCH] fix androidTest error java.io.FileNotFoundException: detect.tflite --- .../lite/examples/detection/DetectorTest.java | 15 +++++++++------ .../object_detection/android/build.gradle | 2 +- .../android/lib_interpreter/build.gradle | 2 -- .../android/lib_task_api/build.gradle | 2 -- 4 files changed, 10 insertions(+), 11 deletions(-) diff --git a/lite/examples/object_detection/android/app/src/androidTest/java/org/tensorflow/lite/examples/detection/DetectorTest.java b/lite/examples/object_detection/android/app/src/androidTest/java/org/tensorflow/lite/examples/detection/DetectorTest.java index e5e07ba5039..7dc82e387b3 100644 --- a/lite/examples/object_detection/android/app/src/androidTest/java/org/tensorflow/lite/examples/detection/DetectorTest.java +++ b/lite/examples/object_detection/android/app/src/androidTest/java/org/tensorflow/lite/examples/detection/DetectorTest.java @@ -29,13 +29,10 @@ import android.graphics.Matrix; import android.graphics.RectF; import android.util.Size; + import androidx.test.ext.junit.runners.AndroidJUnit4; import androidx.test.platform.app.InstrumentationRegistry; -import java.io.IOException; -import java.io.InputStream; -import java.util.ArrayList; -import java.util.List; -import java.util.Scanner; + import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; @@ -44,6 +41,12 @@ import org.tensorflow.lite.examples.detection.tflite.Detector.Recognition; import org.tensorflow.lite.examples.detection.tflite.TFLiteObjectDetectionAPIModel; +import java.io.IOException; +import java.io.InputStream; +import java.util.ArrayList; +import java.util.List; +import java.util.Scanner; + /** Golden test for Object Detection Reference app. */ @RunWith(AndroidJUnit4.class) public class DetectorTest { @@ -63,7 +66,7 @@ public class DetectorTest { public void setUp() throws IOException { detector = TFLiteObjectDetectionAPIModel.create( - InstrumentationRegistry.getInstrumentation().getContext(), + InstrumentationRegistry.getInstrumentation().getTargetContext(), MODEL_FILE, LABELS_FILE, MODEL_INPUT_SIZE, diff --git a/lite/examples/object_detection/android/build.gradle b/lite/examples/object_detection/android/build.gradle index 5bffa360dfc..b140e452d8f 100644 --- a/lite/examples/object_detection/android/build.gradle +++ b/lite/examples/object_detection/android/build.gradle @@ -7,7 +7,7 @@ buildscript { mavenLocal() } dependencies { - classpath 'com.android.tools.build:gradle:4.0.0' + classpath 'com.android.tools.build:gradle:7.2.0' classpath 'de.undercouch:gradle-download-task:4.0.2' // NOTE: Do not place your application dependencies here; they belong // in the individual module build.gradle files diff --git a/lite/examples/object_detection/android/lib_interpreter/build.gradle b/lite/examples/object_detection/android/lib_interpreter/build.gradle index 2d60d2595ee..4f206de5690 100644 --- a/lite/examples/object_detection/android/lib_interpreter/build.gradle +++ b/lite/examples/object_detection/android/lib_interpreter/build.gradle @@ -6,8 +6,6 @@ android { defaultConfig { minSdkVersion 21 targetSdkVersion 30 - versionCode 1 - versionName "1.0" testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" } diff --git a/lite/examples/object_detection/android/lib_task_api/build.gradle b/lite/examples/object_detection/android/lib_task_api/build.gradle index 9ce8bfc7267..5b51c21fb77 100644 --- a/lite/examples/object_detection/android/lib_task_api/build.gradle +++ b/lite/examples/object_detection/android/lib_task_api/build.gradle @@ -6,8 +6,6 @@ android { defaultConfig { minSdkVersion 21 targetSdkVersion 30 - versionCode 1 - versionName "1.0" testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" }