首页 > 解决方案 > change name of native shared library AAR and binary in android studio

问题描述

I'm building a shared library AAR in Anroid Studio (3.4.2)

the name of the build is app-debug_-debug.aar - the project is called app - how do I change the name of the project to foobar so that my library will be called foobar-debug_-debug.aar

also the binary of library.so file with the is called libjni_lib.so and i'd like to rename that to libbarbaz.so too

how to do this?

标签: android

解决方案


要更改二进制名称,我必须做两件事

1)更改文件BINARY_NAME中的CMakeLists.txt

cmake_minimum_required(VERSION 3.4.1)

SET(BINARY_NAME "my_new_binary_name")

然后在几个地方使用它

add_library( ${BINARY_NAME}

...

target_link_libraries( ${BINARY_NAME}

2)更改System.loadLibrary以调用我的新二进制名称

public class Java
{
    static
    {
        System.loadLibrary ("my_new_binary_name");
    }

    public native static void initialiseMyAPP (Context appContext);
}

为了更改库名称,我在复制文件时将文件重命名为主机目标


    rename { String fileName ->
        fileName.replace("old_library_name.aar", "new_library_name.aar")
    }
``

推荐阅读