吾爱破解 - LCG - LSG |安卓破解|病毒分析|www.52pojie.cn

 找回密码
 注册[Register]

QQ登录

只需一步,快速开始

查看: 4623|回复: 16
收起左侧

[Android 分享] 《教我兄弟学Android逆向06 》中关于gradle3.0以上so文件生成

[复制链接]
linghun 发表于 2020-2-4 02:36
本帖最后由 linghun 于 2020-2-4 02:36 编辑

本人小白最近跟帖子走教程发现后面so文件生成用帖子中的方法不行已经被弃用了

根据报错:使用CMake or ndk-build

参考贴:https://www.jianshu.com/p/997ae19a5fae
工具:Android Studio3.2

一丶先通过SDKManager下载:CMake和LLDB
QQ图片20200203203943.png

二丶编写build.gradle
1.在build.gradle的defaultConfig节点下加入:

       //使用Cmake工具
        externalNativeBuild{
            cmake{
                cppFlags ""
                //生成多个版本的so文件
                abiFilters "arm64-v8a", "armeabi-v7a", "x86", "x86_64"
            }
        }


2.在build.gradle的android节点下加入:



    //配置CmakeLists.txt路径

    externalNativeBuild{

        cmake{

            path "CMakeLists.txt"

        }

    }


三丶添加CMakeLists.txt文件到build.gradle文件同级目录下

QQ图片20200204022914.png

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.
#CMakeLists.txt
cmake_minimum_required(VERSION 3.4.1)


# 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.
            # 设置so文件名称.
             JniTest


             # Sets the library as a shared library.
             SHARED
             # 设置这个so文件为共享.


             # Provides a relative path to your source file(s).
             # 设置这个so文件为共享.
             src/main/jni/main.c)


# 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.
                       # 制定目标库.
                       JniTest


                       # Links the target library to the log library
                       # included in the NDK.
                       ${log-lib} )


四丶就可以Rebuild Project

原帖中第五步 配置SO库 不用做就可以得到如下结果:
QQ图片20200204022553.png

免费评分

参与人数 1吾爱币 +1 热心值 +1 收起 理由
Lixinist + 1 + 1 我很赞同!

查看全部评分

发帖前要善用论坛搜索功能,那里可能会有你要找的答案或者已经有人发布过相同内容了,请勿重复发帖。

marlborogolo 发表于 2020-2-4 07:05

楼主厉害 佩服佩服
love514415 发表于 2020-2-4 08:12
社会王『绝世』 发表于 2020-2-4 08:22
会成功的人 发表于 2020-2-4 09:34
谢谢分享
Lixinist 发表于 2020-2-4 09:50
支持。其实也可以在新建项目那里直接选native项目,as会直接帮你搞好。
WA187187 发表于 2020-2-4 10:02
学习中.....
多幸运遇见baby 发表于 2020-2-4 10:56
热心回复!
qq82273391 发表于 2020-2-4 11:07
谢谢楼主分享
hs_f 发表于 2020-2-4 15:38
感谢分享经验。
您需要登录后才可以回帖 登录 | 注册[Register]

本版积分规则 警告:本版块禁止灌水或回复与主题无关内容,违者重罚!

快速回复 收藏帖子 返回列表 搜索

RSS订阅|小黑屋|处罚记录|联系我们|吾爱破解 - LCG - LSG ( 京ICP备16042023号 | 京公网安备 11010502030087号 )

GMT+8, 2024-5-4 19:21

Powered by Discuz!

Copyright © 2001-2020, Tencent Cloud.

快速回复 返回顶部 返回列表