我开始了解 gradle,并使用带有 Android 插件的 Intellij Idea 13.1.3。 我想 build u2020项目并在 Idea 中使用 gradle 时遇到一些麻烦。
导入项目后,我得到的只是单个模块“u2020”,没有依赖项集和无意义的项目结构。 Idea也不识别项目的android框架,看不到类之类的.java文件。
根目录下只有一个 build.gradle 文件。 我应该怎么做才能在 Idea 中运行项目?将 sourceSets 添加到 build.gradle?
更新: 来自 github 链接的 build.gradle:
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:1.0.0'
}
}
// Manifest version information!
def versionMajor = 1
def versionMinor = 0
def versionPatch = 0
def versionBuild = 0 // bump for dogfood builds, public betas, etc.
apply plugin: 'com.android.application'
repositories {
mavenCentral()
}
dependencies {
compile 'com.android.support:support-v4:21.0.3'
compile 'com.squareup.dagger:dagger:1.2.2'
provided 'com.squareup.dagger:dagger-compiler:1.2.2'
compile 'com.squareup.okhttp:okhttp:2.1.0'
compile 'com.squareup.okhttp:okhttp-urlconnection:2.1.0'
compile 'com.squareup.picasso:picasso:2.4.0'
compile 'com.squareup.retrofit:retrofit:1.8.0'
debugCompile 'com.squareup.retrofit:retrofit-mock:1.8.0'
compile 'com.jakewharton:butterknife:6.0.0'
compile 'com.jakewharton.timber:timber:2.5.0'
debugCompile 'com.jakewharton.madge:madge:1.1.1'
debugCompile 'com.jakewharton.scalpel:scalpel:1.1.1'
compile 'io.reactivex:rxjava:1.0.3'
compile 'io.reactivex:rxandroid:0.23.0'
compile 'com.etsy.android.grid:library:1.0.3'
}
def gitSha = 'git rev-parse --short HEAD'.execute([], project.rootDir).text.trim()
def buildTime = new Date().format("yyyy-MM-dd'T'HH:mm'Z'", TimeZone.getTimeZone("UTC"))
def isTravis = "true".equals(System.getenv("TRAVIS"))
def preDexEnabled = "true".equals(System.getProperty("pre-dex", "true"))
android {
compileSdkVersion 21
buildToolsVersion '21.1.1'
dexOptions {
// Skip pre-dexing when running on Travis CI or when disabled via -Dpre-dex=false.
preDexLibraries = preDexEnabled && !isTravis
}
defaultConfig {
minSdkVersion 15
targetSdkVersion 21
versionCode versionMajor * 10000 + versionMinor * 1000 + versionPatch * 100 + versionBuild
versionName "${versionMajor}.${versionMinor}.${versionPatch}"
buildConfigField "String", "GIT_SHA", "\"${gitSha}\""
buildConfigField "String", "BUILD_TIME", "\"${buildTime}\""
}
buildTypes {
debug {
applicationIdSuffix '.dev'
versionNameSuffix '-dev'
}
}
lintOptions {
abortOnError false
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_7
targetCompatibility JavaVersion.VERSION_1_7
}
}
项目中的文件夹
u2020
|
|_debug
| |_AndroidManifest.xml
| |_java
| |_res
| |_assets
|
|_main
| |_androidManifest.xml
| |_java
| |_all other android stuff
|
|_release
| |_java
|
|_build.gradle
|_other stuff
最佳答案
很可能 IJ 的 Gradle 项目导入不支持 Android,并且可以正确导入应用了 java
插件的 Java 项目。 com.android.application
扩展了 java-base
但不是 java
。最简单的解决方案可能是使用 Android Studio。
关于android - 无法在Idea中导入gradle android项目,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27926018/