diff --git a/.gitignore b/.gitignore index e551f3556..ab5fa179a 100644 --- a/.gitignore +++ b/.gitignore @@ -34,3 +34,4 @@ build/ *.iml javadoc/ tessdata/ +.externalNativeBuild \ No newline at end of file diff --git a/build.gradle b/build.gradle index d2a6ef4b2..d4d4106f7 100644 --- a/build.gradle +++ b/build.gradle @@ -6,9 +6,9 @@ buildscript { jcenter() } dependencies { - classpath 'com.android.tools.build:gradle:3.1.1' + classpath 'com.android.tools.build:gradle:3.2.1' classpath 'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.2' - classpath 'com.github.dcendents:android-maven-gradle-plugin:1.4.1' + classpath 'com.github.dcendents:android-maven-gradle-plugin:1.5' } } diff --git a/eyes-two/AndroidManifest.xml b/eyes-two/AndroidManifest.xml index 5ad2f1817..87f104524 100644 --- a/eyes-two/AndroidManifest.xml +++ b/eyes-two/AndroidManifest.xml @@ -20,7 +20,7 @@ android:versionName="1.0" > + android:minSdkVersion="16" + android:targetSdkVersion="22" /> diff --git a/eyes-two/build.gradle b/eyes-two/build.gradle index 9c77d1b7a..14300ce2e 100644 --- a/eyes-two/build.gradle +++ b/eyes-two/build.gradle @@ -6,12 +6,12 @@ Properties properties = new Properties() properties.load(project.rootProject.file('local.properties').newDataInputStream()) android { - compileSdkVersion 27 - buildToolsVersion '27.0.3' + compileSdkVersion 28 + buildToolsVersion '28.0.3' defaultConfig { - minSdkVersion 9 - targetSdkVersion 22 + minSdkVersion 16 + targetSdkVersion 28 versionCode 1 versionName '1.0' } diff --git a/eyes-two/project.properties b/eyes-two/project.properties index 198dc6e33..4f0b5bcc0 100644 --- a/eyes-two/project.properties +++ b/eyes-two/project.properties @@ -10,6 +10,6 @@ # Indicates whether an apk should be generated for each density. split.density=false # Project target. -target=android-9 +target=android-16 android.library=true android.library.reference.1=../tess-two diff --git a/eyes-two/src/main/AndroidManifest.xml b/eyes-two/src/main/AndroidManifest.xml index 5849f968a..b3ba99086 100644 --- a/eyes-two/src/main/AndroidManifest.xml +++ b/eyes-two/src/main/AndroidManifest.xml @@ -14,14 +14,6 @@ limitations under the License. --> - - - + diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 08e8ae50e..0a649815e 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,6 +1,6 @@ -#Thu Apr 19 17:52:32 PDT 2018 +#Wed Dec 19 14:38:04 CET 2018 distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-4.4-all.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-4.6-all.zip diff --git a/tess-two-test/AndroidManifest.xml b/tess-two-test/AndroidManifest.xml index 81c163dca..2ed768e48 100644 --- a/tess-two-test/AndroidManifest.xml +++ b/tess-two-test/AndroidManifest.xml @@ -1,23 +1,13 @@ - - + package="com.googlecode.tesseract.android.test"> - - + - + android:label="@string/app_name"> diff --git a/tess-two-test/build.gradle b/tess-two-test/build.gradle index 0394475b8..f957cb20b 100644 --- a/tess-two-test/build.gradle +++ b/tess-two-test/build.gradle @@ -1,14 +1,16 @@ apply plugin: 'com.android.application' android { - compileSdkVersion 27 - buildToolsVersion '27.0.3' + compileSdkVersion 28 + buildToolsVersion '28.0.3' defaultConfig { - minSdkVersion 9 - targetSdkVersion 22 + minSdkVersion 16 + targetSdkVersion 28 versionCode 1 versionName '1.0' + + testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" } sourceSets { @@ -25,9 +27,16 @@ android { jniLibs.srcDirs = ['libs'] } } + + useLibrary 'android.test.runner' + useLibrary 'android.test.base' } dependencies { implementation project(':tess-two') testImplementation 'junit:junit:4.12' + + // AndroidJUnitRunner and JUnit Rules + androidTestImplementation 'com.android.support.test:runner:1.0.2' + //androidTestImplementation 'com.android.support.test:rules:1.0.2' } \ No newline at end of file diff --git a/tess-two-test/project.properties b/tess-two-test/project.properties index 5824c0067..2c1acefe7 100644 --- a/tess-two-test/project.properties +++ b/tess-two-test/project.properties @@ -9,4 +9,4 @@ android.library.reference.1=../tess-two # Project target. -target=android-9 +target=android-16 diff --git a/tess-two-test/src/com/googlecode/tesseract/android/test/AllTests.java b/tess-two-test/src/com/googlecode/tesseract/android/test/AllTests.java index 5d283002e..885bf5f70 100644 --- a/tess-two-test/src/com/googlecode/tesseract/android/test/AllTests.java +++ b/tess-two-test/src/com/googlecode/tesseract/android/test/AllTests.java @@ -1,12 +1,12 @@ /* * Copyright (C) 2011 Google Inc. - * + * * Licensed under the Apache License, Version 2.0 (the "License"); you may not * use this file except in compliance with the License. You may obtain a copy of * the License at - * + * * http://www.apache.org/licenses/LICENSE-2.0 - * + * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the @@ -16,6 +16,12 @@ package com.googlecode.tesseract.android.test; +import android.content.Context; +import android.content.pm.PackageManager; +import android.os.Build; +import android.os.ParcelFileDescriptor; +import android.os.SystemClock; +import android.support.annotation.NonNull; import android.test.suitebuilder.TestSuiteBuilder; import com.googlecode.leptonica.android.test.ReadFileTest; @@ -23,6 +29,11 @@ import junit.framework.Test; import junit.framework.TestSuite; +import java.io.IOException; + +import static android.support.test.InstrumentationRegistry.getInstrumentation; +import static android.support.test.InstrumentationRegistry.getTargetContext; + /** * To run all suites found in this apk: * $ adb shell am instrument -w \ @@ -49,4 +60,28 @@ public static Test suite() { .includeAllPackagesUnderHere() .build(); } + + public static void grantPermissions(@NonNull String[] permissions) { + if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M) { + return; + } + boolean granted = false; + + Context context = getTargetContext(); + for (String permission : permissions) { + if (context.checkSelfPermission(permission) != PackageManager.PERMISSION_GRANTED) { + try (ParcelFileDescriptor pfd = getInstrumentation().getUiAutomation().executeShellCommand( + "pm grant " + context.getPackageName() + " " + permission)) { + granted = true; + } catch (IOException e) { + e.printStackTrace(); + } + } + } + + if (granted) { + // Wait a while to make sure permission is granted + SystemClock.sleep(2000); + } + } } diff --git a/tess-two-test/src/com/googlecode/tesseract/android/test/TessBaseAPITest.java b/tess-two-test/src/com/googlecode/tesseract/android/test/TessBaseAPITest.java index 1e5277a70..8aa49ecb8 100644 --- a/tess-two-test/src/com/googlecode/tesseract/android/test/TessBaseAPITest.java +++ b/tess-two-test/src/com/googlecode/tesseract/android/test/TessBaseAPITest.java @@ -16,6 +16,7 @@ package com.googlecode.tesseract.android.test; +import android.Manifest; import android.graphics.Bitmap; import android.graphics.Bitmap.CompressFormat; import android.graphics.Canvas; @@ -61,18 +62,24 @@ public class TessBaseAPITest extends TestCase { "eng.tesseract_cube.nn" }; - private static final int DEFAULT_PAGE_SEG_MODE = + private static final int DEFAULT_PAGE_SEG_MODE = TessBaseAPI.PageSegMode.PSM_SINGLE_BLOCK; protected void setUp() throws Exception { super.setUp(); + // Grant permission to use external storage + AllTests.grantPermissions(new String[] { + Manifest.permission.READ_EXTERNAL_STORAGE, + Manifest.permission.WRITE_EXTERNAL_STORAGE, + }); + // Check that the data file(s) exist. for (String languageCode : DEFAULT_LANGUAGE.split("\\+")) { if (!languageCode.startsWith("~")) { - File expectedFile = new File(TESSDATA_PATH + File.separator + + File expectedFile = new File(TESSDATA_PATH + File.separator + languageCode + ".traineddata"); - assertTrue("Make sure that you've copied " + languageCode + + assertTrue("Make sure that you've copied " + languageCode + ".traineddata to " + TESSDATA_PATH, expectedFile.exists()); } } @@ -83,7 +90,7 @@ private void checkCubeData() { for (String expectedFilename : EXPECTED_CUBE_DATA_FILES_ENG) { String expectedFilePath = TESSDATA_PATH + expectedFilename; File expectedFile = new File(expectedFilePath); - assertTrue("Make sure that you've copied " + expectedFilename + + assertTrue("Make sure that you've copied " + expectedFilename + " to " + expectedFilePath, expectedFile.exists()); } } @@ -400,7 +407,7 @@ private void testGetUTF8Text(String language, int ocrEngineMode) { assertTrue("Result was not high-confidence.", lastConfidence > 80); assertTrue("Result bounding box not found.", lastBoundingBox[2] > 0 && lastBoundingBox[3] > 0); - boolean validBoundingRect = lastBoundingRect.left < lastBoundingRect.right + boolean validBoundingRect = lastBoundingRect.left < lastBoundingRect.right && lastBoundingRect.top < lastBoundingRect.bottom; assertTrue("Result bounding box Rect is incorrect.", validBoundingRect); @@ -424,7 +431,7 @@ public void testInit() { public void testInit_ocrEngineMode() { // Attempt to initialize the API. final TessBaseAPI baseApi = new TessBaseAPI(); - boolean result = baseApi.init(TESSBASE_PATH, DEFAULT_LANGUAGE, + boolean result = baseApi.init(TESSBASE_PATH, DEFAULT_LANGUAGE, TessBaseAPI.OEM_TESSERACT_ONLY); assertTrue("Init was unsuccessful.", result); @@ -513,7 +520,7 @@ public void onProgressValues(ProgressValues progressValues) { assertTrue(success); baseApi.setPageSegMode(TessBaseAPI.PageSegMode.PSM_SINGLE_LINE); - baseApi.setVariable(TessBaseAPI.VAR_CHAR_WHITELIST, + baseApi.setVariable(TessBaseAPI.VAR_CHAR_WHITELIST, leftInput + rightInput); baseApi.setImage(bmp); @@ -630,13 +637,13 @@ public void testSetPageSegMode() { assertTrue(success); // Check the default page segmentation mode. - assertEquals("Found unexpected default page segmentation mode.", + assertEquals("Found unexpected default page segmentation mode.", baseApi.getPageSegMode(), DEFAULT_PAGE_SEG_MODE); // Ensure that the page segmentation mode can be changed. final int newPageSegMode = TessBaseAPI.PageSegMode.PSM_SINGLE_CHAR; baseApi.setPageSegMode(newPageSegMode); - assertEquals("Found unexpected page segmentation mode.", + assertEquals("Found unexpected page segmentation mode.", baseApi.getPageSegMode(), newPageSegMode); // Attempt to shut down the API. diff --git a/tess-two-test/src/com/googlecode/tesseract/android/test/TessPdfRendererTest.java b/tess-two-test/src/com/googlecode/tesseract/android/test/TessPdfRendererTest.java index a5a4a25cf..fc46df095 100644 --- a/tess-two-test/src/com/googlecode/tesseract/android/test/TessPdfRendererTest.java +++ b/tess-two-test/src/com/googlecode/tesseract/android/test/TessPdfRendererTest.java @@ -21,6 +21,7 @@ import junit.framework.TestCase; +import android.Manifest; import android.annotation.SuppressLint; import android.graphics.Bitmap; import android.graphics.Canvas; @@ -41,6 +42,17 @@ public class TessPdfRendererTest extends TestCase { @SuppressLint("SdCardPath") private final static String OUTPUT_PATH = "/sdcard/"; + @Override + protected void setUp() throws Exception { + super.setUp(); + + // Grant permission to use external storage + AllTests.grantPermissions(new String[] { + Manifest.permission.READ_EXTERNAL_STORAGE, + Manifest.permission.WRITE_EXTERNAL_STORAGE, + }); + } + @SmallTest public void testCreate() { // Attempt to initialize the API. diff --git a/tess-two/AndroidManifest.xml b/tess-two/AndroidManifest.xml index d115c9699..b1bfd751c 100644 --- a/tess-two/AndroidManifest.xml +++ b/tess-two/AndroidManifest.xml @@ -14,13 +14,6 @@ limitations under the License. --> - - - + diff --git a/tess-two/build.gradle b/tess-two/build.gradle index 9a236281c..7a12c4dd0 100644 --- a/tess-two/build.gradle +++ b/tess-two/build.gradle @@ -8,12 +8,12 @@ Properties properties = new Properties() properties.load(project.rootProject.file('local.properties').newDataInputStream()) android { - compileSdkVersion 27 - buildToolsVersion '27.0.3' + compileSdkVersion 28 + buildToolsVersion '28.0.3' defaultConfig { - minSdkVersion 9 - targetSdkVersion 22 + minSdkVersion 16 + targetSdkVersion 28 versionCode 1 versionName '1.0' consumerProguardFiles 'proguard-rules.pro' @@ -61,7 +61,7 @@ android { dependencies { implementation fileTree(dir: 'libs', include: ['*.jar']) - implementation "com.android.support:support-annotations:27.1.1" + implementation "com.android.support:support-annotations:28.0.0" } diff --git a/tess-two/jni/Application.mk b/tess-two/jni/Application.mk index f734e7c37..a46c6c856 100644 --- a/tess-two/jni/Application.mk +++ b/tess-two/jni/Application.mk @@ -1,6 +1,6 @@ -APP_STL := gnustl_static +APP_STL := c++_static APP_ABI := armeabi-v7a x86 arm64-v8a x86_64 APP_OPTIM := release -APP_PLATFORM := android-9 +APP_PLATFORM := android-16 APP_CPPFLAGS += -fexceptions -frtti NDK_TOOLCHAIN_VERSION := clang diff --git a/tess-two/jni/com_googlecode_tesseract_android/src/android/jni/Application.mk b/tess-two/jni/com_googlecode_tesseract_android/src/android/jni/Application.mk index ef8a2153f..babe740de 100644 --- a/tess-two/jni/com_googlecode_tesseract_android/src/android/jni/Application.mk +++ b/tess-two/jni/com_googlecode_tesseract_android/src/android/jni/Application.mk @@ -9,5 +9,5 @@ endif # Specify the hash namespace that we're using, based on the APP_STL we're using. APP_CFLAGS += -Werror -DHASH_NAMESPACE=__gnu_cxx -Wno-error=deprecated-register APP_PLATFORM := android-16 -APP_STL := gnustl_static +APP_STL := c++_static NDK_TOOLCHAIN_VERSION := clang diff --git a/tess-two/project.properties b/tess-two/project.properties index 91b6a278b..616f300c3 100644 --- a/tess-two/project.properties +++ b/tess-two/project.properties @@ -9,4 +9,4 @@ android.library=true # Project target. -target=android-9 +target=android-16