Rob*_*kus 34 android android-studio android-gradle-plugin
我已经将Android库创建为Android Studio模块.添加为我的根模块的依赖项.编码时,我可以从库包中导入任何类,但在我尝试运行应用程序时,我遇到了错误package some.mylibrary.project does not exist.
build.gradle根模块
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.12.+'
}
}
apply plugin: 'com.android.application'
dependencies {
compile fileTree(dir: 'libs', include: '*.jar')
compile 'com.android.support:appcompat-v7:20.+'
compile 'com.google.android.gms:play-services:5.+'
compile project(':libraries:mylibrary')
}
android {
compileSdkVersion 17
buildToolsVersion "20.0.0"
lintOptions {
disable 'InvalidPackage'
checkReleaseBuilds false
abortOnError false
}
***
}
Run Code Online (Sandbox Code Playgroud)
build.gradle库模块
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.12.+'
}
}
apply plugin: 'com.android.application'
apply plugin: 'idea'
android {
compileSdkVersion 17
buildToolsVersion "20.0.0"
*****
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
}
Run Code Online (Sandbox Code Playgroud)
settings.gradle
include ':libraries:mylibrary'
Run Code Online (Sandbox Code Playgroud)
PS我必须提到项目是从Eclipse IDE导出的,因此项目结构与默认项目结构不同.
Sco*_*rta 14
如果您有一个库模块,它不能使用apply plugin: 'com.android.application'模块定义中的语句,否则构建将在您看到时无声地失败.使用apply plugin: 'com.android.library'来代替.
已经提交了一个错误请求构建系统在发生这种情况时大声失败而不是默默地:https://code.google.com/p/android/issues/detail?id = 76725
Cod*_*ife 14
适用于Android Studio 2.2.2
是的,在库模块中,它不能com.android.application在模块定义中使用apply plugin:语句,是的,使用apply plugin:com.android.library而不是.(仍然在lib模块中)
但是你必须做以下事情:
同时命名您的lib模块时请避免使用大写字母.
小智 5
上面的答案有些欠缺如果你在 Kotlin 中项目 java add 得到这个错误
项目 build.gradle 添加
ext.kotlin_version = ‘1.3.21’
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
Run Code Online (Sandbox Code Playgroud)
应用程序 build.gradle
apply plugin: 'kotlin-android-extensions'
apply plugin: 'kotlin-android'
Run Code Online (Sandbox Code Playgroud)
科特林
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
Run Code Online (Sandbox Code Playgroud)
参考:https ://medium.com/mindorks/enabling-kotlin-support-for-a-current-only-java-android-project-98c75e04384a
| 归档时间: |
|
| 查看次数: |
62397 次 |
| 最近记录: |