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:
来源:https://stackoverflow.com/questions/41154462/building-tess-two-into-a-project-using-android-studios-gradle-build