使用 Android Studio 的 gradle build 将 tess-two 构建到项目中 [英] Building tess-two into a project using Android Studio's gradle build

本文介绍了使用 Android Studio 的 gradle build 将 tess-two 构建到项目中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有关于将 tess-two 项目集成到 Android Studio 中的 Android 项目的答案,但很多都已过时,没有使用此处定义的当前功能:

<块引用>

使用 Android Studio 2.2 及更高版本,您可以使用 NDK 将 C 和 C++ 代码编译为本机库,然后使用 IDE 的集成构建系统 Gradle 将其打包到您的 APK 中.然后,您的 Java 代码可以通过 Java 本机接口 (JNI) 调用本机库中的函数

使用 Android Studio 中的功能,而不是外部文件放置、操作和命令行工具?因此,将 *.so 文件的构建和创建放入 IDE.具体来说,仅使用 Android Studio集成构建系统 (Gradle),如

<强>2.将 Tess-Two 导入项目

2b.添加任何需要的插件

3.在主 Activity 中添加代码以获得原生功能

4.配置 Android Studio 构建以便使用本机功能

这里需要详细说明

解决方案

4.为原生功能配置 Android Studio 构建

4a.将 C++ 项目与 Gradle 链接

首先,检查 tess-two 项目的构建文件.您可以选择 CMakeLists.txt 或 Android.mk 文件.目前两者都受支持.

在这种情况下,我使用了 ndk-build,这似乎是集成原生代码的好选择.

有关详细信息,请参阅

这样做可以避免e=87"错误:

有关该主题的更多信息,请参阅

4d.构建项目并检查 .apk 文件中的 .so 文件

需要很长时间的构建现在应该完成了.验证 .apk 文件是否包含在构建期间创建的 .so 文件.使用静态初始化程序中的 tess-two 库,在您的 Android 设备上运行项目:

There are answers about getting the tess-two project integrated into an Android project within Android Studio, but many are out-dated and none used the current capabilities defined here:

Using Android Studio 2.2 and higher, you can use the NDK to compile C and C++ code into a native library and package it into your APK using Gradle, the IDE's integrated build system. Your Java code can then call functions in your native library through the Java Native Interface (JNI)

What specific steps would be required to make tess-two functionality a part of the resulting APK, using functionality within Android Studio, rather than external file placement, manipulation and command line tools? So taking the building, creation of *.so files into the IDE. Specifically using just Android Studio's integrated build system (Gradle) as described here.

1. Start a new project

2. Import Tess-Two into the project

2b. Add any needed plug-ins

3. Add code in the main activity to get native functionality

4. Configure Android Studio build so that native functionality is available

This is where the specifics are required

解决方案

4. Configure Android Studio build for native functionality

4a. Link C++ Project with Gradle

First, check the tess-two project for build files. You may select CMakeLists.txt or Android.mk files. Both are currently supported.

In this case, I used ndk-build, which seemed like a good bet for integrating the native code.

For more information, see Android Studio documentation

4b. Manage Long Commands

In Windows, errors may be encountered if the command length grows too large. To prevent problems, use LOCAL_SHORT_COMMANDS AND APP_SHORT_COMMANDS in the Android.mk file.

The "e=87" error is what you are avoiding by doing this:

For more on that topic, see stackoverflow question about error 87.

4c. Add Module Dependency for tess-two

In File > Project Structure > Dependencies use the + to add the tess-two dependency:

4d. Build the Project and check .apk file for .so files

The build, which takes a long time, should complete now. Validate that the .apk file contains the .so files, created during the build. With the tess-two libraries in an static initializer, run the project on your Android device:

这篇关于使用 Android Studio 的 gradle build 将 tess-two 构建到项目中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆