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

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

问题描述

有关于将tess-two项目集成到 Android Studio 中的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:

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

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)

使用 Android Studio 中的功能而不是外部文件放置,操作和命令行工具,将tess-two功能作为结果APK的一部分需要采取哪些具体步骤?因此,将* .so文件构建并创建到IDE中.具体来说,仅使用 Android Studio 集成的构建系统(Gradle),如

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.开始一个新项目

2.将Tess-Two导入到项目中

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

3.在主要活动中添加代码以获得本机功能

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

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

这是要求提供详细信息的地方

推荐答案

4.将 Android Studio 构建配置为具有本机功能

4. Configure Android Studio build for native functionality

4a.将C ++项目与Gradle关联

首先,检查tess-two项目中的生成文件.您可以选择CMakeLists.txt或Android.mk文件.目前都支持.

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

在这种情况下,我使用了ndk-build,这似乎是集成本机代码的不错选择.

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

有关更多信息,请参见 Android Studio文档

For more information, see Android Studio documentation

4b.管理长命令

在Windows中,如果命令长度变得太大,则可能会遇到错误.为防止出现问题,请在Android.mk文件中使用LOCAL_SHORT_COMMANDSAPP_SHORT_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.

执行此操作可避免出现"e = 87"错误:

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

有关该主题的更多信息,请参见 stackoverflow问题关于错误87 .

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

4c.为测试二添加模块依赖性

文件>项目结构>依赖关系中,使用 + 添加tess-two依赖关系:

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

4d.生成项目并检查.apk文件中的.so文件

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

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构建将tess-two集成到项目中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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