创建日期:公元2022年05月26日
修改日期:-
文章状态:未完待续
平台:Windows7 + Android Studio
适用于/使用:安卓开发(Java、C++)
———————————————————————————————————————————
目录
1.新建项目:
2.导入相关资源:
3.修改相关内容:
4.其它:
1.新建项目:
File
New
New Project...
选择Nactive C++
Next
填入Name、Package Name、Language选择Java,其它默认
Next
Finish
(耐心等待创建成功)
2.导入相关资源:
cpp文件夹下导入:bzip文件夹+bspatch.c文件
3.修改相关内容:
cpp/CMakeLists.txt修改为:
# For more information about using CMake with Android Studio, read the
# documentation: https://d.android.com/studio/projects/add-native-code.html
# Sets the minimum version of CMake required to build the native library.
cmake_minimum_required(VERSION 3.18.1)
file(GLOB bzip_source bzip/*.c)
# Declares and names the project.
project("具体实际为你的项目名小写")
# Creates and names a library, sets it as either STATIC
# or SHARED, and provides the relative paths to its source code.
# You can define multiple libraries, and CMake builds them for you.
# Gradle automatically packages shared libraries with your APK.
add_library( # Sets the name of the library.
具体实际为你的项目名小写
# Sets the library as a shared library.
SHARED
# Provides a relative path to your source file(s).
native-lib.cpp
bspatch.c
${bzip_source})
include_directories(bzip)
# Searches for a specified prebuilt library and stores the path as a
# variable. Because CMake includes system libraries in the search path by
# default, you only need to specify the name of the public NDK library
# you want to add. CMake verifies that the library exists before
# completing its build.
find_library( # Sets the name of the path variable.
log-lib
# Specifies the name of the NDK library that
# you want CMake to locate.
log)
# Specifies libraries CMake should link to your target library. You
# can link multiple libraries, such as libraries you define in this
# build script, prebuilt third-party libraries, or system libraries.
target_link_libraries( # Specifies the target library.
具体实际为你的项目名小写
# Links the target library to the log library
# included in the NDK.
${log-lib})
cpp/native-lib.cpp修改为:
#include#include extern "C" { extern int main(int argc,char * argv[]); } extern "C" JNIEXPORT void JNICALL Java_包名_java文件名_native_1bspatch(JNIEnv *env, jobject instance, jstring oldApk_, jstring newApk_, jstring patchFile_) { const char *oldApk = env->GetStringUTFChars(oldApk_, 0); const char *newApk = env->GetStringUTFChars(newApk_, 0); const char *pathFile = env->GetStringUTFChars(patchFile_, 0); char * argv[4] = {"", const_cast (oldApk), const_cast (newApk), const_cast (pathFile)}; main(4, argv); env->ReleaseStringUTFChars(oldApk_, oldApk); env->ReleaseStringUTFChars(newApk_, newApk); env->ReleaseStringUTFChars(patchFile_, pathFile); }
对应的,上述的java文件中的函数应改为:
private native void native_bspatch(String oldApk,String newApk,String patchFile);
4.其它:
之后即可测试是否能发布成apk
如何发布成apkhttps://blog.csdn.net/weixin_53743049/article/details/123091276
———————————————————————————————————————————
——原创!转发请注明出处



