简体   繁体   English

Android gradle实验插件路线图

[英]Android gradle experimental plugin roadmap

At our company we are developing an Android SDK that contains both Java and native part. 在我们公司,我们正在开发一个包含Java和本机部分的Android SDK。 We pack the SDK in AAR format that contains all resources, java classes and native bits. 我们以AAR格式打包SDK,其中包含所有资源,java类和本机位。 According to AAR specification, native libraries should be placed inside jni folder inside AAR bundle. 根据AAR规范,本机库应放在AAR包内的jni文件夹中。 Since current gradle plugin does not support advanced NDK uses cases and since we have a very mature Android.mk file that has evolved over 3 years of development, we prepare AAR by calling custom shell script from gradle task. 由于当前的gradle插件不支持高级NDK用例,并且由于我们有一个非常成熟的Android.mk文件已经发展了3年,我们通过从gradle任务调用自定义shell脚本来准备AAR。 This shell script builds the NDK with ndk-build command and the task that runs this script is put as a dependency of javaCompile task (there are multiple flavors of our code and each flavor has its own rules for NDK which are preloaded from a definition file and then given to ndk-build as command-line arguments). 这个shell脚本使用ndk-build命令构建NDK,运行此脚本的任务作为javaCompile任务的依赖项(我们的代码有多种风格,每种风格都有自己的NDK规则,这些规则是从定义文件中预先加载的然后将ndk-build作为命令行参数提供)。

Finally, when everything gets compiled, we have a Copy task which copies the native libs into jni folder inside build/intermediates/bundles (the folder that eventually gets zipped into AAR). 最后,当所有内容都被编译时,我们有一个Copy任务,它将本机库复制到build / intermediates / bundles(最终被压缩到AAR中的文件夹)中的jni文件夹中。 This worked correctly until we updated our project to use gradle plugin v1.5.0. 这工作正常,直到我们更新我们的项目以使用gradle插件v1.5.0。

In v1.5.0 something called Transform API was introduced into plugin. 在v1.5.0中,插件中引入了一个名为Transform API的东西。 Although we do not use this, this Transform step does some transforming of native libs in task transformNative_libsWithSyncJniLibsForFlavorNameBuildTypeName which happens somewhere after we have already copied our libs into jni folder and causes deletion of all data in jni folder. 虽然我们不使用这个,这个变换一步确实在之后我们已经复制了我们的库到JNI文件夹碰巧的地方,并导致所有数据的缺失JNI文件夹任务transformNative_libsWithSyncJniLibsForFlavorNameBuildTypeName本地库的一些转换。 This finally results with AAR that does not contain native libs and crashes as soon as native methods are required. 这最终导致AAR在需要本机方法时不包含本机库和崩溃。

We workarounded this issue by using project.tasks[taskName] to obtain that task and make sure it happens before we copy our libs into jni folder. 我们通过使用project.tasks[taskName]来获取该任务并确保在我们将libs复制到jni文件夹之前确实发生了这个问题。

However, having this problem has started to worry us if and when will the gradle-experimental plugin (the only that currently supports NDK) be put out of experimental phase and will become a standard for building NDK code. 然而,有了这个问题,我们开始担心我们是否以及何时将gradle实验插件(目前仅支持NDK的插件)推出实验阶段,并将成为构建NDK代码的标准。

We experimented a bit with that experimental plugin and besides different syntax (why???) it does not support debugging native code as part of library module (gdb files are not packaged into AAR and jniDebuggable flag does not exist anymore). 我们尝试了一下实验插件,除了不同的语法(为什么???),它不支持调试本机代码作为库模块的一部分(gdb文件未打包到AAR中,jniDebuggable标志不再存在)。

Does anyone know when this plugin will reach a stable API and will be ready for use in production builds? 有谁知道这个插件何时会达到一个稳定的API,并准备好在生产版本中使用? We want to plan ahead our migration from calling ndk-build from shellscript to gradle-only NDK build with same feature parity (plus free support for C++ editing from Android Studio, which is not possible with current configuration, so we rely on different editor for JNI glue code). 我们希望提前计划从调用ndk-build从shellscript到仅使用gradle的NDK构建具有相同的功能奇偶校验(以及从Android Studio免费支持C ++编辑,这对于当前配置是不可能的,因此我们依赖于不同的编辑器 JNI胶水代码)。

I don't have a roadmap, but if you follow the dependencies, you'll see that the Android experimental plugin is still experimental because the new Gradle object model is still experimental. 我没有路线图,但是如果你遵循依赖关系,你会发现Android实验插件仍然是实验性的,因为新的Gradle对象模型仍然是实验性的。 I'd expect that the Android Studio plugin won't be stable until the underlying Gradle code is stable. 我希望Android Studio插件在基础Gradle代码稳定之前不会稳定。

That said: although the syntax differences are frustrating, they are usually fairly easy to apply. 这就是说:虽然语法差异令人沮丧,但它们通常很容易应用。 More importantly, the experimental plugin does offer fairly good debugging support. 更重要的是,实验插件确实提供了相当好的调试支持。 It does not use gdb (it uses lldb by default) and it doesn't rely on the jniDebuggable flag. 它不使用gdb(它默认使用lldb)并且它不依赖于jniDebuggable标志。 The fact that you're looking for these makes me think that you know a lot about how ndk-gdb works, and have perhaps built your own system that relies on that knowledge. 您正在寻找这些这一事实让我觉得您对ndk-gdb的工作原理了解很多,并且可能构建了自己的系统,依赖于这些知识。 Have you tried simply pressing the "Debug" button in Android Studio? 您是否尝试过按Android Studio中的“调试”按钮? It should work fine if your C++ code is in your main project. 如果您的C ++代码在主项目中,它应该可以正常工作。 (It seems to have some issues setting breakpoints in library projects, unfortunately.) (不幸的是,似乎在库项目中设置断点有一些问题。)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM