简体   繁体   English

如何通过仅暴露其核心模块来导入多模块SDK项目

[英]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 工作的项目,该项目包括:

  • an app module for demo一个用于演示的应用模块
  • a module called mainSdkModule一个名为 mainSdkModule 的模块
  • other minor modules that are used in the mainSdkModule (lets say moduleA and moduleB) mainSdkModule 中使用的其他次要模块(比如说 moduleA 和 moduleB)

the mainSdkModule imports moduleA and moduleB this way: mainSdkModule以这种方式导入moduleAmoduleB

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?如何在核心中包含moduleAmoduleB并为那些导入 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.

相关问题 如何在多模块、单一活动、仅撰写、项目中显示来自 Composables 或 ViewModels 的小吃店 - How to show snackbars from Composables or ViewModels on a multi-module, single activity, Compose only, project 如何在Gradle多模块项目中使用ObjectBox? - How to use ObjectBox in Gradle multi-module project? 如何为多模块项目创建汇总的 Jacoco 报告? - How to create an aggregated Jacoco report for a multi-module project? 在多模块项目中使用 Firebase - Using Firebase in a multi-module project Android多模块项目因TypeNotPresentException失败 - Android multi-module project fails with TypeNotPresentException 在多模块项目中集成 Crashlytics - Integrating Crashlytics in a multi-module project Android Studio仅为多模块项目中不依赖模块的模块生成R文件 - Android Studio generates R file only for modules with no module dependencies in multi-module project 在Android Studio 0.3.1中导入多模块Android项目时出现“必须指定路径!”错误 - “A path must be specified!” error during multi-module Android project import in Android Studio 0.3.1 如何为我的图书馆项目或多模块项目生成一些文档站点 - How can I generate some document site for my library project or multi-module project RobolectricTestRunner在多模块Maven项目中找不到清单文件 - RobolectricTestRunner cannot find manifest file in multi-module maven project
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM