在 Android AAR 中添加播放服务依赖
Add play services dependency in Android AAR
我正在尝试创建使用播放服务的 android aar。我在库 gradle 文件中添加了 playservices 依赖项。但是当 aar 在发布模式运行时导出时它不起作用。
如何在aar中添加google播放服务?
请帮忙
您可能需要在 adding your library as a dependency 中检查这些步骤:
Add the library to your project in either of the following ways (if you created the library module within the same project, then it's already there and you can skip this step):
Add the compiled AAR (or JAR) file (the library must be already built):
- Click File > New > New Module.
- Click Import .JAR/.AAR Package then click Next.
- Enter the location of the compiled AAR or JAR file then click Finish.
Import the library module to your project (the library source becomes part of your project):
- Click File > New > Import Module.
- Enter the location of the library module directory then click Finish.
The library module is copied to your project, so you can actually edit the library code. If you want to maintain a single version of the library code, then this is probably not what you want and you should instead add the compiled AAR file as described above.
- Make sure the library is listed at the top of your
settings.gradle
file, as shown here for a library named "my-library-module":
include ':app', ':my-library-module'
- Open the app module's build.gradle file and add a new line to the dependencies block as shown in the following snippet:
dependencies {
compile project(":my-library-module")
}
- Click Sync Project with Gradle Files.
但是,如果它是您想要重用的应用程序模块,您可以按照以下步骤将其转换为库模块 convert an app module to a library module:
- 打开模块级
build.gradle
文件。
- 删除
applicationId
的行。只有 Android 应用程序模块可以定义它。
在文件的顶部,您应该看到以下内容:
apply plugin: 'com.android.application'
将其更改为以下内容:
apply plugin: 'com.android.library'
保存文件并单击 工具 > Android > 与 Gradle 同步项目
文件.
有关更详细的信息,请参阅此 documentation. Also. this related 可以提供更多见解。
由于播放服务现在包含 aar 库而不是 jar,我们无法将 aar 文件与库合并,即另一个 aar 文件。而且,因此不可能在 aar 文件中添加播放服务。这个问题的最佳解决方案是谁在使用你制作的 aar,告诉他们在项目中添加 play-services 依赖。
- 向您的项目添加一个新模块并select 导入 .JAR/.AAR 包.
- 添加模块后,按如下方式进行:项目结构 → Select 应用程序模块 → 依赖项选项卡 → 单击 + 按钮 → select 您添加的模块 → 确定
我正在尝试创建使用播放服务的 android aar。我在库 gradle 文件中添加了 playservices 依赖项。但是当 aar 在发布模式运行时导出时它不起作用。 如何在aar中添加google播放服务? 请帮忙
您可能需要在 adding your library as a dependency 中检查这些步骤:
Add the library to your project in either of the following ways (if you created the library module within the same project, then it's already there and you can skip this step):
Add the compiled AAR (or JAR) file (the library must be already built):
- Click File > New > New Module.
- Click Import .JAR/.AAR Package then click Next.
- Enter the location of the compiled AAR or JAR file then click Finish.
Import the library module to your project (the library source becomes part of your project):
- Click File > New > Import Module.
- Enter the location of the library module directory then click Finish.
The library module is copied to your project, so you can actually edit the library code. If you want to maintain a single version of the library code, then this is probably not what you want and you should instead add the compiled AAR file as described above.
- Make sure the library is listed at the top of your
settings.gradle
file, as shown here for a library named "my-library-module":
include ':app', ':my-library-module'
- Open the app module's build.gradle file and add a new line to the dependencies block as shown in the following snippet:
dependencies {
compile project(":my-library-module")
}
- Click Sync Project with Gradle Files.
但是,如果它是您想要重用的应用程序模块,您可以按照以下步骤将其转换为库模块 convert an app module to a library module:
- 打开模块级
build.gradle
文件。 - 删除
applicationId
的行。只有 Android 应用程序模块可以定义它。 在文件的顶部,您应该看到以下内容:
apply plugin: 'com.android.application'
将其更改为以下内容:
apply plugin: 'com.android.library'
保存文件并单击 工具 > Android > 与 Gradle 同步项目 文件.
有关更详细的信息,请参阅此 documentation. Also. this related
由于播放服务现在包含 aar 库而不是 jar,我们无法将 aar 文件与库合并,即另一个 aar 文件。而且,因此不可能在 aar 文件中添加播放服务。这个问题的最佳解决方案是谁在使用你制作的 aar,告诉他们在项目中添加 play-services 依赖。
- 向您的项目添加一个新模块并select 导入 .JAR/.AAR 包.
- 添加模块后,按如下方式进行:项目结构 → Select 应用程序模块 → 依赖项选项卡 → 单击 + 按钮 → select 您添加的模块 → 确定