缺少创建新 AS 项目并在安装时在我的设备上填充 lib 文件夹的步骤 [英] Missing step to create a new AS project and get a lib folder populated on my device upon installation
问题描述
我希望在我安装 APK 时,我的 APK 中的库可以从固定位置在我的设备上使用.
I want the libs present in my APK to be available on my device from a fixed location when I install my APK.
我根据我现有的项目打开了关于这个问题的另一个问题.这一次,我从头开始了一个全新的项目,以减少未知数并使我的问题更容易解决.
I opened another question about this issue based on my existing project. This time, I started a brand new project from scratch in order to reduce the unknowns and make my question simpler to resolve.
使用 Android Studio 4.0.1,我执行以下操作:
With Android Studio 4.0.1, I do the following:
启动一个新的 Android Studio 项目
Start a new Android Studio project
选择本机 C++
设置项目名称为 test
Set project name to test
选择 Java 作为语言
Select Java as language
使用默认工具链
构建 ->制作项目
在项目视图下,我验证我的 app-debug.apk
有一个 lib
文件夹,其中包含几个子目录,每个子目录至少包含 libnative-lib.so
是根据默认的 CMakeLists.txt 规则为此项目构建的.
Under the project view, I verify that my app-debug.apk
has a lib
folder containing a few subdirectories, each with at least the libnative-lib.so
that was built for this project accordingly to the default CMakeLists.txt rules.
我希望在安装 APK 时可以从我的设备访问这个 .so(我有一个更复杂的项目,我在其中创建了 .so,以便我想从 APK 外部访问).
I would like this .so to be accessible from my device when I install my APK (I have a more complex project in which I create .so that I want accessible from outside the APK).
但是,从我的项目文件夹中,当我运行时:
However, from my project folder, when I run:
c:\Users\xxx\AndroidStudioProjects\test>adb install app\build\outputs\apk\debug\app-debug.apk
Performing Streamed Install
Success
c:\Users\xxx\AndroidStudioProjects\test>adb shell ls /data/data/com.example.test
cache
code_cache
我尝试过的其他更改
以下进一步的更改都没有让我看到 /data/data/com.example.test
将
android.bundle.enableUncompressedNativeLibs=false
添加到gradle.properties
已添加
android {
...
sourceSets.main {
jniLibs.srcDirs = ['libs']
jni.srcDirs = []
}
到 build.gradle
不要对此做任何更改.
to build.gradle
do not change anything to this.
将 set(distribution_DIR ${CMAKE_SOURCE_DIR}/libs)
添加到 CMakeLists.txt
推荐答案
本机库不在 /data/data/your.app
中,而是在 /data/app/your 中.aapp-
,例如在我的目标上:
Native libraries are not placed in /data/data/your.app
but in /data/app/your.aapp-<key-hash>==/lib/<ABI>
, for example on my target:
hikey960:/ # cd /data/app/com.example.dlopen-6BSPeAN9VvjFlCxIzLHX9A\=\=/lib/arm64
hikey960:/data/app/com.example.dlopen-6BSPeAN9VvjFlCxIzLHX9A==/lib/arm64 # ls -als
total 1352
4 drwxr-xr-x 2 system system 4096 2020-11-06 12:43 .
4 drwxr-xr-x 3 system system 4096 2020-11-06 12:43 ..
1044 -rwxr-xr-x 1 system system 1067256 1981-01-01 01:01 libnative-lib.so
300 -rwxr-xr-x 1 system system 305360 1981-01-01 01:01 libplugin.so
此外,本机库默认存档,无法访问,要提取它们,需要在 AndroidManifest.xml
中设置 android:extractNativeLibs=true"
(例如像这里:https://github.com/nkh-lab/ndk-dlopen/blob/master/dlopen/app/src/main/AndroidManifest.xml).
Also native libraries are archived by default and can not be accessible, for extracting them it is needed to set android:extractNativeLibs="true"
in AndroidManifest.xml
(for example like here: https://github.com/nkh-lab/ndk-dlopen/blob/master/dlopen/app/src/main/AndroidManifest.xml).
这篇关于缺少创建新 AS 项目并在安装时在我的设备上填充 lib 文件夹的步骤的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!