Skip to content
This repository has been archived by the owner on Mar 17, 2022. It is now read-only.

Commit

Permalink
Merge pull request #256 from Robyer/update-sdk
Browse files Browse the repository at this point in the history
Update to support latest Android Studio
  • Loading branch information
rmtheis authored Jan 12, 2019
2 parents f465360 + 531b275 commit ac41529
Show file tree
Hide file tree
Showing 18 changed files with 106 additions and 67 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -34,3 +34,4 @@ build/
*.iml
javadoc/
tessdata/
.externalNativeBuild
4 changes: 2 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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'
}
}

Expand Down
4 changes: 2 additions & 2 deletions eyes-two/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
android:versionName="1.0" >

<uses-sdk
android:minSdkVersion="9"
android:targetSdkVersion="9" />
android:minSdkVersion="16"
android:targetSdkVersion="22" />

</manifest>
8 changes: 4 additions & 4 deletions eyes-two/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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'
}
Expand Down
2 changes: 1 addition & 1 deletion eyes-two/project.properties
Original file line number Diff line number Diff line change
Expand Up @@ -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
10 changes: 1 addition & 9 deletions eyes-two/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,6 @@
limitations under the License.
-->

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.googlecode.eyesfree.ocr"
android:versionCode="4"
android:versionName="0.6.1"
android:installLocation="auto">

<uses-sdk
android:minSdkVersion="9"
android:targetSdkVersion="22" />
<manifest package="com.googlecode.eyesfree.ocr">

</manifest>
4 changes: 2 additions & 2 deletions gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -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
16 changes: 3 additions & 13 deletions tess-two-test/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,23 +1,13 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.googlecode.tesseract.android.test"
android:versionCode="1"
android:versionName="1.0" >

<uses-sdk
android:minSdkVersion="9"
android:targetSdkVersion="22" />
package="com.googlecode.tesseract.android.test">

<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />

<instrumentation
android:name="android.test.InstrumentationTestRunner"
android:targetPackage="com.googlecode.tesseract.android.test" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />

<application
android:icon="@drawable/icon"
android:label="@string/app_name" >
<uses-library android:name="android.test.runner" />
android:label="@string/app_name">
</application>

</manifest>
17 changes: 13 additions & 4 deletions tess-two-test/build.gradle
Original file line number Diff line number Diff line change
@@ -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 {
Expand All @@ -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'
}
2 changes: 1 addition & 1 deletion tess-two-test/project.properties
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,4 @@

android.library.reference.1=../tess-two
# Project target.
target=android-9
target=android-16
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -16,13 +16,24 @@

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;

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 \
Expand All @@ -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);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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());
}
}
Expand All @@ -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());
}
}
Expand Down Expand Up @@ -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);

Expand All @@ -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);
Expand Down Expand Up @@ -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);

Expand Down Expand Up @@ -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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@

import junit.framework.TestCase;

import android.Manifest;
import android.annotation.SuppressLint;
import android.graphics.Bitmap;
import android.graphics.Canvas;
Expand All @@ -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.
Expand Down
9 changes: 1 addition & 8 deletions tess-two/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,6 @@
limitations under the License.
-->

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.googlecode.tesseract.android"
android:versionCode="1"
android:versionName="1.0" >

<uses-sdk
android:minSdkVersion="9"
android:targetSdkVersion="22" />
<manifest package="com.googlecode.tesseract.android">

</manifest>
10 changes: 5 additions & 5 deletions tess-two/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down Expand Up @@ -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"
}


Expand Down
4 changes: 2 additions & 2 deletions tess-two/jni/Application.mk
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 1 addition & 1 deletion tess-two/project.properties
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,4 @@

android.library=true
# Project target.
target=android-9
target=android-16

0 comments on commit ac41529

Please sign in to comment.