如何使项目兼容 64 位

how to make project 64 bit compatible

android 体系结构的最新变化强制所有开发人员使其 android 应用程序支持 64 位。

我已经查看了文档。但正如它显示的那样,寻找一个 "lib" 文件夹,该文件夹可能包含“.so”文件。

我试过同样的东西,但显然我找不到 "lib" 文件夹开头,我的应用程序完全用 java 编写,没有原生(C,C++)代码。

任何人都可以建议我可以做什么或如何确保我的应用程序支持 64 位或如何使用 .so 文件获取库。

简答:

如果您没有原生 (NDK) 代码,即您只编写了 Java/Dex 代码,那么您无需执行任何操作。

如果您有本机代码(或库),则需要提供它们的 64 位版本。


详细答案(解释):

Google 游戏团队建议执行以下操作:

If you haven't yet, we encourage you to begin work for the 64-bit requirement as soon as possible. Many apps are written entirely in non-native code (e.g. the Java programming language or Kotlin) and will not need code changes.

Please note that we are not making changes to our policy on 32-bit support. Google Play will continue to deliver apps with 32-bit native code to 32-bit devices. The requirement means that those apps will need to have a 64-bit version as well.

To help you make the transition, we've prepared documentation on how to check whether your app already supports 64-bit and how to become 64-bit compliant.

We're also providing a high-level timeline below.

总结上述引用段落中提供的文档 link:

If your app uses only code written in the Java programming language or Kotlin, including any libraries or SDKs, your app is already ready for 64-bit devices. If your app uses any native code, or you are unsure if it does, you will need to assess your app and take action.

.....

The simplest way to check for 64-bit libraries is to inspect the structure of your APK file. When built, the APK will be packaged with any native libraries needed by the app. Native libraries are stored in various folders based on the ABI. It is not required to support every 64-bit architecture, but for each native 32-bit architecture you support you must include the corresponding 64-bit architecture.

For the ARM architecture, the 32-bit libraries are located in armeabi-v7a. The 64-bit equivalent is arm64-v8a.

For the x86 architecture, look for x86 for 32-bit and x86_64 for 64-bit.

The first thing to do is ensure that you have native libraries in both of these folders....

如果您的 APK 已经有 NDK 代码和 64 位库,请按照以下步骤操作:

Most Android Studio projects use Gradle as the underlying build system, so this section applies to both cases. Enabling builds for your native code is as simple as adding the arm64-v8a and/or x86_64, depending on the architecture(s) you wish to support, to the ndk.abiFilters setting in your app's 'build.gradle' file:

// Your app's build.gradle
apply plugin: 'com.android.app'

// Your app's build.gradle    apply plugin: 'com.android.app'

android {
   compileSdkVersion 27
   defaultConfig {
     appId "com.google.example.64bit"
     minSdkVersion 15
     targetSdkVersion 28
     versionCode 1
     versionName "1.0"
     ndk.abiFilters 'armeabi-v7a', 'arm64-v8a', 'x86', 'x86_64'   
// ...

希望对您有所帮助。

因此,如果您真的想在本机 java 项目中创建 .so 文件。按照以下步骤操作:

第 1 步:要安装 NDK、CMake 和 LLDB,请执行以下操作: 打开项目后,单击工具 > SDK 管理器。 单击 SDK 工具选项卡。 安装 NDK、CMake 和 LLDB。 第 2 步:完成这些步骤后,在 project/src/main.

中创建一个 cpp 文件夹

第 3 步:在 cpp 文件夹下,添加 native-lib.cpp。

第 4 步:在项目文件夹下创建 SMakeLists.txt 文件。

第 5 步:在 Gradle 中添加外部库:

android{
     externalNativeBuild {
       cmake {
          path "CMakeLists.txt"
        }
     }

}

defaultConfig {
  ndk.abiFilters 'armeabi-v7a','arm64-v8a','x86','x86_64'
  externalNativeBuild {
    cmake {
        cppFlags ""
    }
}

}