java - 将android包添加到java模块(android studio)
问题描述
抱歉,这是我第一次遇到这种问题,我不知道该怎么办。
我正在开发一个包含两个 java 模块(Module1、Module2)的项目
主项目的 build.gardle:
apply plugin: 'com.android.application'
android {
compileSdkVersion 29
buildToolsVersion "29.0.3"
defaultConfig {
applicationId "com.client.howara"
minSdkVersion 24
targetSdkVersion 29
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
implementation project(':Module1')
implementation project(':Module2')
implementation fileTree(include: ['*.jar'], dir: 'libs')
testImplementation 'junit:junit:4.13'
implementation .....
}
模块 1 的 build.gardle:
apply plugin: 'java'
dependencies {
implementation fileTree(include: ['*.jar'], dir: 'libs')
implementation project(':Module2')
}
模块 2 的 build.gradle:
apply plugin: 'java'
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
}
当我尝试将 android 包添加到 Module1 时,出现以下错误:
例子:
error: package android.os does not exist
import android.os.Build;
我需要修改 module1 build.gradle 吗?如果是的话怎么办?
感谢您的帮助,并为我的无知感到抱歉
解决方案
编辑
您已定义module1
为java
库。因此,将禁止导入任何android
工件以将其保留为java
库。
如果您真的想在 中添加android
工件module1
,则需要通过执行以下操作转换module1
为库:android
Module1 的 BuildScript:
// Remove this
apply plugin: 'java'
// Instead add this
apply plugin: 'com.android.library'
我认为您正在做的事情很好,但是您无法有效地陈述您的问题。
您当前发生的情况Gradle
BuildScripts
是:您的App
依赖于Module1
和Module2
,您的Module1
依赖于Module2
且您的Module2
不依赖于任何一个app
或Module1
。
App
/ \
Module1 \
\ \
\ \
\ \
Module2
推荐阅读
- bash - 在 Bash kill 错误中创建新进程后
- visual-studio-code - 仅删除一个标志,而不是所有标志直到最后一个选项卡
- mysql - 如何在一个视图中显示超过 1 个表格
- charts - Highstock/highcharts - yAxis 标题宽度
- python - 使用不和谐机器人更新数据库。为什么机器人不识别和更新数据库?
- azureservicebus - 使用 MassTransit 路由到开发环境
- android - Android Bodymovin 动画转 mp4 视频
- php - 获取由 file_put_contents() 生成的文件的 url;
- javascript - 如何独立设置输入元素的样式
- generics - Kotlin - Generic function storing incorrect type in map successfully