[英]How to import multi-module SDK project by exposing its core module only
I am developing a project which should work as an Android sdk, the project includes:我正在开发一个应该作为 Android sdk 工作的项目,该项目包括:
the mainSdkModule
imports moduleA
and moduleB
this way: mainSdkModule
以这种方式导入moduleA
和moduleB
:
implementation project(':moduleA')
implementation project(':moduleB')
I am publishing the whole project as an SDK that I want to use in another app project.我将整个项目发布为 SDK,我想在另一个应用程序项目中使用它。 To test the integration of this SDK I am temporarily publishing it to my local maven folder.为了测试这个 SDK 的集成,我暂时将它发布到我的本地 maven 文件夹。 What happens is that when I import the sdk into the app project, the build fails with the following error:发生的情况是,当我将 sdk 导入应用程序项目时,构建失败并出现以下错误:
Could not find sdk-main-package:moduleA:unspecified.
Required by:
project :mainSdkModule > sdk-main-package:core:1.0.0
I could avoid this error by publishing each module as an indipendent library but I need to keep them internal without exposing them.我可以通过将每个模块发布为独立库来避免此错误,但我需要将它们保留在内部而不暴露它们。
Is it normal that the app project asks for a dependency that isn't even supposed to be visible by other projects besides the sdk one?除了 sdk 之外,应用程序项目要求的依赖项甚至不应该被其他项目看到,这是否正常? How can I include moduleA
and moduleB
inside the core and grant access to them for those who import the SDK without exposing these internal modules on maven?如何在核心中包含moduleA
和moduleB
并为那些导入 SDK 的人授予对它们的访问权限,而不在 maven 上公开这些内部模块?
In Android Studio在 Android 工作室
Do This:做这个:
1-File -> Project Structure 1-文件->项目结构
2-select Dependencies from left menu 2-从左侧菜单中选择依赖项
3-select app you see + and - in top middle of screen, click on + 3-选择您看到的应用程序 + 和 - 在屏幕顶部中间,单击 +
4-select Module Dependency and tick your mainSdkModule and add it to your app module 4-选择模块依赖并勾选您的 mainSdkModule 并将其添加到您的应用程序模块
5-select mainSdkModule and click + and tick ModuleA and ModuleB 5-选择 mainSdkModule 并单击 + 并勾选 ModuleA 和 ModuleB
6-apply and build your project 6-应用并构建您的项目
Modules A and B are declared as external dependencies and will be referenced as such in the pom.xml file.模块 A 和 B 被声明为外部依赖项,并将在 pom.xml 文件中被引用。 Something like this:像这样的东西:
<dependency>
<groupId>sdk-main-package</groupId>
<artifactId>moduleA</artifactId>
<version>unspecified</version>
<scope>compile</scope>
</dependency>
What you want is to create a fat jar or a fat aar .你想要的是创建一个胖 jar或一个胖 aar 。 A fat jar/aar is a jar/aar file that also includes the dependencies (instead of referencing them as external dependencies). fat jar/aar 是一个 jar/aar 文件,它还包含依赖项(而不是将它们作为外部依赖项引用)。 I don't know if your SDK needs to be a jar file or an aar file and if you don't know either then you can find out the difference eg here: Android Archive Library (aar) vs standard jar . I don't know if your SDK needs to be a jar file or an aar file and if you don't know either then you can find out the difference eg here: Android Archive Library (aar) vs standard jar .
If you need a fat jar then you can use the Shadow
plugin: https://imperceptiblethoughts.com/shadow/introduction .如果你需要一个胖子 jar那么你可以使用Shadow
插件: https://imperceptiblethoughts.com/shadow/introduction 。
If you need a fat aar then you can eg use this: https://medium.com/android-news/android-fat-aar-from-gradle-892038facc87 .如果你需要一个胖子,那么你可以使用这个: https://medium.com/android-news/android-fat-aar-from-gradle-892038facc87 。 There are other solutions but I haven't personally tested any of them so don't know which ones really work.还有其他解决方案,但我没有亲自测试过其中任何一个,所以不知道哪些真正有效。 If you google fat aar
you'll get plenty of hits and I hope one of them solves your problem.如果你在谷歌上搜索fat aar
,你会得到很多点击,我希望其中一个能解决你的问题。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.