Android问题5:引用自己的Modules

本文详细介绍了在Android Studio中如何正确地将一个模块作为依赖添加到另一个项目中。通过File->ProjectStructure,选择Dependencies选项卡,然后添加ModulesDependency,轻松实现模块间的依赖。同时,提供了一种更直接的方法,即在代码中手动添加implementationproject路径,以达到同样的效果。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

小白好难啊!!!

选择中 File -> Project Structrue,选中 Dependencies选项卡,选中要引用其他模块的项目(app),点击右边的+。

点击+按钮后,有个列表选择,选择Modules Dependencies ,勾选要引用的模块即可。

 

下面选项, 使用默认的 implementation 即可,完成。

放弃界面操作,直接在代码里添加下述2行也可以达到相同的效果。

implementation project(path: ':xilib')

implementation project(path: ':xilibweb')

 

 

 

 

 

 

Executing tasks: [:app:assembleDebug] in project D:\TestProject\MyApplication > Task :app:createDebugVariantModel UP-TO-DATE > Task :app:preBuild UP-TO-DATE > Task :app:preDebugBuild UP-TO-DATE > Task :app:mergeDebugNativeDebugMetadata NO-SOURCE > Task :app:compileDebugAidl NO-SOURCE > Task :app:compileDebugRenderscript NO-SOURCE > Task :app:generateDebugBuildConfig UP-TO-DATE > Task :app:javaPreCompileDebug UP-TO-DATE > Task :app:checkDebugAarMetadata UP-TO-DATE AGPBI: {"kind":"warning","text":"Your project has set `android.useAndroidX=true`, but configuration `:app:debugRuntimeClasspath` still contains legacy support libraries, which may cause runtime issues.\nThis behavior will not be allowed in Android Gradle plugin 8.0.\nPlease use only AndroidX dependencies or set `android.enableJetifier=true` in the `gradle.properties` file to migrate your project to AndroidX (see https://developer.android.com/jetpack/androidx/migrate for more info).\nThe following legacy support libraries are detected:\n:app:debugRuntimeClasspath -> com.android.support:support-compat:28.0.0\n:app:debugRuntimeClasspath -> com.android.support:support-compat:28.0.0 -> com.android.support:support-annotations:28.0.0\n:app:debugRuntimeClasspath -> com.android.support:support-compat:28.0.0 -> com.android.support:collections:28.0.0\n:app:debugRuntimeClasspath -> com.android.support:support-compat:28.0.0 -> android.arch.lifecycle:runtime:1.1.1\n:app:debugRuntimeClasspath -> com.android.support:support-compat:28.0.0 -> android.arch.lifecycle:runtime:1.1.1 -> android.arch.lifecycle:common:1.1.1\n:app:debugRuntimeClasspath -> com.android.support:support-compat:28.0.0 -> android.arch.lifecycle:runtime:1.1.1 -> android.arch.core:common:1.1.1\n:app:debugRuntimeClasspath -> com.android.support:support-compat:28.0.0 -> com.android.support:versionedparcelable:28.0.0","sources":[{}]} > Task :app:generateDebugResValues UP-TO-DATE > Task :app:mapDebugSourceSetPaths UP-TO-DATE > Task :app:generateDebugResources UP-TO-DATE > Task :app:mergeDebugResources UP-TO-DATE > Task :app:packageDebugResources UP-TO-DATE > Task :app:parseDebugLocalResources UP-TO-DATE > Task :app:createDebugCompatibleScreenManifests UP-TO-DATE > Task :app:extractDeepLinksDebug UP-TO-DATE > Task :app:processDebugMainManifest FAILED [androidx.versionedparcelable:versionedparcelable:1.1.1] C:\Users\wangsen\.gradle\caches\transforms-3\4b621581b14be943fef7e9025808a5ef\transformed\versionedparcelable-1.1.1\AndroidManifest.xml Warning: Namespace 'androidx.versionedparcelable' used in: androidx.versionedparcelable:versionedparcelable:1.1.1, com.android.support:versionedparcelable:28.0.0. D:\TestProject\MyApplication\app\src\main\AndroidManifest.xml:22:18-91 Error: Attribute application@appComponentFactory value=(android.support.v4.app.CoreComponentFactory) from [com.android.support:support-compat:28.0.0] AndroidManifest.xml:22:18-91 is also present at [androidx.core:core:1.7.0] AndroidManifest.xml:24:18-86 value=(androidx.core.app.CoreComponentFactory). Suggestion: add 'tools:replace="android:appComponentFactory"' to <application> element at AndroidManifest.xml:7:5-25:19 to override. See https://developer.android.com/r/studio-ui/build/manifest-merger for more information about the manifest merger. > Task :app:mergeDebugShaders UP-TO-DATE > Task :app:compileDebugShaders NO-SOURCE > Task :app:generateDebugAssets UP-TO-DATE > Task :app:mergeDebugAssets UP-TO-DATE > Task :app:compressDebugAssets UP-TO-DATE > Task :app:processDebugJavaRes NO-SOURCE > Task :app:desugarDebugFileDependencies UP-TO-DATE > Task :app:mergeDebugJniLibFolders UP-TO-DATE > Task :app:mergeDebugNativeLibs NO-SOURCE > Task :app:stripDebugDebugSymbols NO-SOURCE > Task :app:validateSigningDebug UP-TO-DATE > Task :app:writeDebugAppMetadata UP-TO-DATE > Task :app:writeDebugSigningConfigVersions UP-TO-DATE > Task :app:checkDebugDuplicateClasses FAILED > Task :app:mergeDebugJavaResource FAILED FAILURE: Build completed with 3 failures. 1: Task failed with an exception. ----------- * What went wrong: Execution failed for task ':app:processDebugMainManifest'. > Manifest merger failed with multiple errors, see logs * Try: > Run with --stacktrace option to get the stack trace. > Run with --info or --debug option to get more log output. > Run with --scan to get full insights. ============================================================================== 2: Task failed with an exception. ----------- * What went wrong: Execution failed for task ':app:checkDebugDuplicateClasses'. > A failure occurred while executing com.android.build.gradle.internal.tasks.CheckDuplicatesRunnable > Duplicate class android.support.v4.app.INotificationSideChannel found in modules core-1.7.0-runtime (androidx.core:core:1.7.0) and support-compat-28.0.0-runtime (com.android.support:support-compat:28.0.0) Duplicate class android.support.v4.app.INotificationSideChannel$Stub found in modules core-1.7.0-runtime (androidx.core:core:1.7.0) and support-compat-28.0.0-runtime (com.android.support:support-compat:28.0.0) Duplicate class android.support.v4.app.INotificationSideChannel$Stub$Proxy found in modules core-1.7.0-runtime (androidx.core:core:1.7.0) and support-compat-28.0.0-runtime (com.android.support:support-compat:28.0.0) Duplicate class android.support.v4.graphics.drawable.IconCompatParcelizer found in modules core-1.7.0-runtime (androidx.core:core:1.7.0) and support-compat-28.0.0-runtime (com.android.support:support-compat:28.0.0) Duplicate class android.support.v4.os.IResultReceiver found in modules core-1.7.0-runtime (androidx.core:core:1.7.0) and support-compat-28.0.0-runtime (com.android.support:support-compat:28.0.0) Duplicate class android.support.v4.os.IResultReceiver$Stub found in modules core-1.7.0-runtime (androidx.core:core:1.7.0) and support-compat-28.0.0-runtime (com.android.support:support-compat:28.0.0) Duplicate class android.support.v4.os.IResultReceiver$Stub$Proxy found in modules core-1.7.0-runtime (androidx.core:core:1.7.0) and support-compat-28.0.0-runtime (com.android.support:support-compat:28.0.0) Duplicate class android.support.v4.os.ResultReceiver found in modules core-1.7.0-runtime (androidx.core:core:1.7.0) and support-compat-28.0.0-runtime (com.android.support:support-compat:28.0.0) Duplicate class android.support.v4.os.ResultReceiver$1 found in modules core-1.7.0-runtime (androidx.core:core:1.7.0) and support-compat-28.0.0-runtime (com.android.support:support-compat:28.0.0) Duplicate class android.support.v4.os.ResultReceiver$MyResultReceiver found in modules core-1.7.0-runtime (androidx.core:core:1.7.0) and support-compat-28.0.0-runtime (com.android.support:support-compat:28.0.0) Duplicate class android.support.v4.os.ResultReceiver$MyRunnable found in modules core-1.7.0-runtime (androidx.core:core:1.7.0) and support-compat-28.0.0-runtime (com.android.support:support-compat:28.0.0) Duplicate class androidx.core.graphics.drawable.IconCompatParcelizer found in modules core-1.7.0-runtime (androidx.core:core:1.7.0) and support-compat-28.0.0-runtime (com.android.support:support-compat:28.0.0) Duplicate class androidx.core.internal.package-info found in modules core-1.7.0-runtime (androidx.core:core:1.7.0) and support-compat-28.0.0-runtime (com.android.support:support-compat:28.0.0) Duplicate class androidx.versionedparcelable.CustomVersionedParcelable found in modules versionedparcelable-1.1.1-runtime (androidx.versionedparcelable:versionedparcelable:1.1.1) and versionedparcelable-28.0.0-runtime (com.android.support:versionedparcelable:28.0.0) Duplicate class androidx.versionedparcelable.NonParcelField found in modules versionedparcelable-1.1.1-runtime (androidx.versionedparcelable:versionedparcelable:1.1.1) and versionedparcelable-28.0.0-runtime (com.android.support:versionedparcelable:28.0.0) Duplicate class androidx.versionedparcelable.ParcelField found in modules versionedparcelable-1.1.1-runtime (androidx.versionedparcelable:versionedparcelable:1.1.1) and versionedparcelable-28.0.0-runtime (com.android.support:versionedparcelable:28.0.0) Duplicate class androidx.versionedparcelable.ParcelImpl found in modules versionedparcelable-1.1.1-runtime (androidx.versionedparcelable:versionedparcelable:1.1.1) and versionedparcelable-28.0.0-runtime (com.android.support:versionedparcelable:28.0.0) Duplicate class androidx.versionedparcelable.ParcelImpl$1 found in modules versionedparcelable-1.1.1-runtime (androidx.versionedparcelable:versionedparcelable:1.1.1) and versionedparcelable-28.0.0-runtime (com.android.support:versionedparcelable:28.0.0) Duplicate class androidx.versionedparcelable.ParcelUtils found in modules versionedparcelable-1.1.1-runtime (androidx.versionedparcelable:versionedparcelable:1.1.1) and versionedparcelable-28.0.0-runtime (com.android.support:versionedparcelable:28.0.0) Duplicate class androidx.versionedparcelable.VersionedParcel found in modules versionedparcelable-1.1.1-runtime (androidx.versionedparcelable:versionedparcelable:1.1.1) and versionedparcelable-28.0.0-runtime (com.android.support:versionedparcelable:28.0.0) Duplicate class androidx.versionedparcelable.VersionedParcel$1 found in modules versionedparcelable-1.1.1-runtime (androidx.versionedparcelable:versionedparcelable:1.1.1) and versionedparcelable-28.0.0-runtime (com.android.support:versionedparcelable:28.0.0) Duplicate class androidx.versionedparcelable.VersionedParcel$ParcelException found in modules versionedparcelable-1.1.1-runtime (androidx.versionedparcelable:versionedparcelable:1.1.1) and versionedparcelable-28.0.0-runtime (com.android.support:versionedparcelable:28.0.0) Duplicate class androidx.versionedparcelable.VersionedParcelParcel found in modules versionedparcelable-1.1.1-runtime (androidx.versionedparcelable:versionedparcelable:1.1.1) and versionedparcelable-28.0.0-runtime (com.android.support:versionedparcelable:28.0.0) Duplicate class androidx.versionedparcelable.VersionedParcelStream found in modules versionedparcelable-1.1.1-runtime (androidx.versionedparcelable:versionedparcelable:1.1.1) and versionedparcelable-28.0.0-runtime (com.android.support:versionedparcelable:28.0.0) Duplicate class androidx.versionedparcelable.VersionedParcelStream$FieldBuffer found in modules versionedparcelable-1.1.1-runtime (androidx.versionedparcelable:versionedparcelable:1.1.1) and versionedparcelable-28.0.0-runtime (com.android.support:versionedparcelable:28.0.0) Duplicate class androidx.versionedparcelable.VersionedParcelable found in modules versionedparcelable-1.1.1-runtime (androidx.versionedparcelable:versionedparcelable:1.1.1) and versionedparcelable-28.0.0-runtime (com.android.support:versionedparcelable:28.0.0) Duplicate class androidx.versionedparcelable.VersionedParcelize found in modules versionedparcelable-1.1.1-runtime (androidx.versionedparcelable:versionedparcelable:1.1.1) and versionedparcelable-28.0.0-runtime (com.android.support:versionedparcelable:28.0.0) Go to the documentation to learn how to <a href="d.android.com/r/tools/classpath-sync-errors">Fix dependency resolution errors</a>. * Try: > Run with --stacktrace option to get the stack trace. > Run with --info or --debug option to get more log output. > Run with --scan to get full insights. ============================================================================== 3: Task failed with an exception. ----------- * What went wrong: Execution failed for task ':app:mergeDebugJavaResource'. > A failure occurred while executing com.android.build.gradle.internal.tasks.MergeJavaResWorkAction > 2 files found with path 'META-INF/androidx.core_core.version' from inputs: - C:\Users\wangsen\.gradle\caches\transforms-3\0b22a6b07b3e498281e2fdb9d93c9c6b\transformed\support-compat-28.0.0\jars\classes.jar - C:\Users\wangsen\.gradle\caches\transforms-3\0212d0c0c0b99c5d00c15a82a811f4d1\transformed\core-1.7.0\jars\classes.jar Adding a packagingOptions block may help, please refer to https://developer.android.com/reference/tools/gradle-api/7.4/com/android/build/api/dsl/ResourcesPackagingOptions for more information * Try: > Run with --stacktrace option to get the stack trace. > Run with --info or --debug option to get more log output. > Run with --scan to get full insights. ============================================================================== * Get more help at https://help.gradle.org BUILD FAILED in 436ms 22 actionable tasks: 3 executed, 19 up-to-date
07-10
Duplicate class android.support.v4.app.INotificationSideChannel found in modules core-1.9.0.aar -> core-1.9.0-runtime (androidx.core:core:1.9.0) and support-compat-24.2.1.aar -> support-compat-24.2.1-runtime (com.android.support:support-compat:24.2.1) Duplicate class android.support.v4.app.INotificationSideChannel$Stub found in modules core-1.9.0.aar -> core-1.9.0-runtime (androidx.core:core:1.9.0) and support-compat-24.2.1.aar -> support-compat-24.2.1-runtime (com.android.support:support-compat:24.2.1) Duplicate class android.support.v4.app.INotificationSideChannel$Stub$Proxy found in modules core-1.9.0.aar -> core-1.9.0-runtime (androidx.core:core:1.9.0) and support-compat-24.2.1.aar -> support-compat-24.2.1-runtime (com.android.support:support-compat:24.2.1) Duplicate class android.support.v4.os.IResultReceiver found in modules core-1.9.0.aar -> core-1.9.0-runtime (androidx.core:core:1.9.0) and support-compat-24.2.1.aar -> support-compat-24.2.1-runtime (com.android.support:support-compat:24.2.1) Duplicate class android.support.v4.os.IResultReceiver$Stub found in modules core-1.9.0.aar -> core-1.9.0-runtime (androidx.core:core:1.9.0) and support-compat-24.2.1.aar -> support-compat-24.2.1-runtime (com.android.support:support-compat:24.2.1) Duplicate class android.support.v4.os.IResultReceiver$Stub$Proxy found in modules core-1.9.0.aar -> core-1.9.0-runtime (androidx.core:core:1.9.0) and support-compat-24.2.1.aar -> support-compat-24.2.1-runtime (com.android.support:support-compat:24.2.1) Duplicate class android.support.v4.os.ResultReceiver found in modules core-1.9.0.aar -> core-1.9.0-runtime (androidx.core:core:1.9.0) and support-compat-24.2.1.aar -> support-compat-24.2.1-runtime (com.android.support:support-compat:24.2.1) Duplicate class android.support.v4.os.ResultReceiver$1 found in modules core-1.9.0.aar -> core-1.9.0-runtime (androidx.core:core:1.9.0) and support-compat-24.2.1.aar -> support-compat-24.2.1-runtime (com.android.support:support-compat:24.2.1) Duplicate class android.support.v4.os.ResultReceiver$MyResultReceiver found in modules core-1.9.0.aar -> core-1.9.0-runtime (androidx.core:core:1.9.0) and support-compat-24.2.1.aar -> support-compat-24.2.1-runtime (com.android.support:support-compat:24.2.1) Duplicate class android.support.v4.os.ResultReceiver$MyRunnable found in modules core-1.9.0.aar -> core-1.9.0-runtime (androidx.core:core:1.9.0) and support-compat-24.2.1.aar -> support-compat-24.2.1-runtime (com.android.support:support-compat:24.2.1)
最新发布
07-12
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值