Android 工作室在 Windows 上启动问题
Android studio starting issue on Windows
我刚刚安装了 android studio 并更新了 sdk。我创建了一个新项目,但似乎无法编译。 gradle 同步有问题:
Error:(29, 0) Could not find method android() for arguments [build_st17khxxb7irr63f8isja72t$_run_closure4@3d9ba855] on root project 'MyApplication' of type org.gradle.api.Project.
这是我的清单文件:
<?xml version="1.0" encoding="utf-8"?>
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:supportsRtl="true"
android:theme="@style/AppTheme" >
<activity android:name=".MainActivity" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
一些无用的词,因为代码太多
这是 build.gradle 文件:
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.2.3'
}
}
allprojects {
repositories {
jcenter()
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
subprojects {
ext {
compileSdkVersion = 22
buildToolsVersion = '25.0.1'
}
}
android{
compileSdkVersion 22
buildToolsVersion '25.0.1'
dexOptions {
incremental true
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_6
targetCompatibility JavaVersion.VERSION_1_6
}
}
dependencies {
compile files('app/libs/junit-4.12-JavaDoc.jar')
}
据我了解,您是在谈论 gradle 构建问题。如果我没看错的话,有一个简单的解决方法。
- 打开gradle.build
- 找到android{
在下面粘贴这段代码:
compileSdkVersion 24
buildToolsVersion "23.0.3
那么它应该是这样的:
android {
compileSdkVersion 24
buildToolsVersion "23.0.3"
此 link 将帮助您解决 build.gradle 问题。
apply plugin: 'com.android.application'
android {
compileSdkVersion 25
buildToolsVersion "25.0.0"
defaultConfig {
applicationId "com.example.myapplication"
minSdkVersion 16
targetSdkVersion 25
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
exclude group: 'com.android.support', module: 'support-annotations'
})
compile 'com.android.support:appcompat-v7:25.0.1'
testCompile 'junit:junit:4.12'
}
我刚刚安装了 android studio 并更新了 sdk。我创建了一个新项目,但似乎无法编译。 gradle 同步有问题:
Error:(29, 0) Could not find method android() for arguments [build_st17khxxb7irr63f8isja72t$_run_closure4@3d9ba855] on root project 'MyApplication' of type org.gradle.api.Project.
这是我的清单文件:
<?xml version="1.0" encoding="utf-8"?>
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:supportsRtl="true"
android:theme="@style/AppTheme" >
<activity android:name=".MainActivity" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
一些无用的词,因为代码太多
这是 build.gradle 文件:
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.2.3'
}
}
allprojects {
repositories {
jcenter()
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
subprojects {
ext {
compileSdkVersion = 22
buildToolsVersion = '25.0.1'
}
}
android{
compileSdkVersion 22
buildToolsVersion '25.0.1'
dexOptions {
incremental true
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_6
targetCompatibility JavaVersion.VERSION_1_6
}
}
dependencies {
compile files('app/libs/junit-4.12-JavaDoc.jar')
}
据我了解,您是在谈论 gradle 构建问题。如果我没看错的话,有一个简单的解决方法。
- 打开gradle.build
- 找到android{
在下面粘贴这段代码:
compileSdkVersion 24 buildToolsVersion "23.0.3
那么它应该是这样的:
android { compileSdkVersion 24 buildToolsVersion "23.0.3"
此 link 将帮助您解决 build.gradle 问题。
apply plugin: 'com.android.application'
android {
compileSdkVersion 25
buildToolsVersion "25.0.0"
defaultConfig {
applicationId "com.example.myapplication"
minSdkVersion 16
targetSdkVersion 25
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
exclude group: 'com.android.support', module: 'support-annotations'
})
compile 'com.android.support:appcompat-v7:25.0.1'
testCompile 'junit:junit:4.12'
}