我知道有类似的问题,但我是android开发的新手,我需要学习如何在build.gradle项目文件中导入一个定义存储库和依赖项的示例。 经过几次尝试,我无法弄清楚哪种方法正确......
示例是https://github.com/neokree/MaterialNavigationDrawer
当我在android studio中加载项目时,我收到错误“找不到配置名称'默认'。”,这没关系..我知道我必须修改build.grandle文件
repositories {
mavenCentral()
}
dependencies {
compile 'it.neokree:MaterialNavigationDrawer:1.3.3'
}
但是我必须添加/替换这些行?在buildscript区域?在所有项目中?如果我尝试更改某些内容,我会收到“未找到Gradle DSL方法:'compile()'”错误或修复插件版本警告。
原始build.grandle
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:1.0.1'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
jcenter()
maven { url "https://oss.sonatype.org/content/repositories/snapshots/" }
}
}
答案 0 :(得分:1)
您的问题出在MaterialNavigationDrawer项目中的setting.gradle文件中。如你所见
include ':app', ':MaterialNavigationDrawerModule'
它需要MaterialNavigationDrawerModule项目来构建。转到新>导入模块并导入MaterialNavigationDrawerModule。 将MaterialNavigationDrawer \ app中的build.gradle更新为
apply plugin: 'com.android.application'
android {
compileSdkVersion 23
buildToolsVersion "23.0.0"
defaultConfig {
applicationId "it.neokree.materialnavigationdrawer"
minSdkVersion 10
targetSdkVersion 23
versionCode 1
versionName '1.0'
}
buildTypes {
release {
//runProguard false
//proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
productFlavors {
}
}
dependencies {
compile 'com.android.support:appcompat-v7:23.0.1'
compile project(':MaterialNavigationDrawerModule')
}
将MaterialNavigationDrawer \ MaterialNavigationDrawerModule中的build.gradle更新为
apply plugin: 'com.android.library'
android {
compileSdkVersion 23
buildToolsVersion "23.0.0"
defaultConfig {
minSdkVersion 10
targetSdkVersion 23
versionCode 1
versionName 'dev'
}
buildTypes {
release {
}
}
productFlavors {
}
}
dependencies {
compile 'com.android.support:appcompat-v7:23.0.1'
compile 'com.balysv:material-ripple:1.0.1'
}
在MainActivity中,我删除了缺少的导入
并重写Intent
到
现在它正在运作。