Android hello world 应用程序中的工作室构建错误
Android studio build error in hello world application
我正在尝试在 Android Studio 中构建基本的 hello world 应用程序,遵循 youtube 上的 thenewboston tutorial。我使用所有默认设置创建了一个新项目。 (Android API 14: Android 4.0 (冰淇淋三明治))
当我尝试 运行 应用程序时,出现以下错误:
错误:(7, 17)
Resource id cannot be an empty string (at 'id' with value '@+id/').
错误:任务“:app:processDebugResources”执行失败。
com.android.ide.common.process.ProcessException: org.gradle.process.internal.ExecException: Process 'command '/Users/abhinavmoudgil95/Library/Android/sdk/build-tools/22.0.1/aapt'' finished with non-zero exit value 1
错误截图可以查看here.
规格如下:
- Android Studio 1.2.1.1
- 运行 在 Macbook Pro OS X: 10.10.3 (Yosemite)
- 构建工具版本:22.0.1
项目文件:
activity_main.xml
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent"
android:layout_height="match_parent" android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:paddingBottom="@dimen/activity_vertical_margin" tools:context=".MainActivity"
android:id="@+id/">
<TextView android:text="@string/hello_world" android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</RelativeLayout>
build.gradle(项目:MyApplication)
apply plugin: 'com.android.application'
android {
compileSdkVersion 22
buildToolsVersion "22.0.1"
defaultConfig {
applicationId "com.example.abhinavmoudgil95.myapplication"
minSdkVersion 14
targetSdkVersion 22
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:22.1.1'
}
build.grade(模块:应用)
apply plugin: 'com.android.application'
android {
compileSdkVersion 22
buildToolsVersion "22.0.1"
defaultConfig {
applicationId "com.example.abhinavmoudgil95.myapplication"
minSdkVersion 14
targetSdkVersion 22
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:22.1.1'
}
我对 android 开发完全陌生。所以请尽量回答简单。
稍作修改:
您没有在 RelativeLayout
中的 android:id="@+id/"
中定义 id
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent"
android:layout_height="match_parent" android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:paddingBottom="@dimen/activity_vertical_margin" tools:context=".MainActivity"
android:id="@+id/layout">
<TextView android:text="@string/hello_world" android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</RelativeLayout>
当您为 xml 中的任何 view
定义 android:id
preoperies 时,必须提供这样的唯一 ID,因此您不能像您在 ur 中所做的那样留下空白 ID xml.
删除这一行:
android:id="@+id/"
或
添加一些唯一的 ID 名称:
android:id="@+id/relativeLayout"
我正在尝试在 Android Studio 中构建基本的 hello world 应用程序,遵循 youtube 上的 thenewboston tutorial。我使用所有默认设置创建了一个新项目。 (Android API 14: Android 4.0 (冰淇淋三明治))
当我尝试 运行 应用程序时,出现以下错误:
错误:(7, 17)
Resource id cannot be an empty string (at 'id' with value '@+id/').
错误:任务“:app:processDebugResources”执行失败。
com.android.ide.common.process.ProcessException: org.gradle.process.internal.ExecException: Process 'command '/Users/abhinavmoudgil95/Library/Android/sdk/build-tools/22.0.1/aapt'' finished with non-zero exit value 1
错误截图可以查看here.
规格如下:
- Android Studio 1.2.1.1
- 运行 在 Macbook Pro OS X: 10.10.3 (Yosemite)
- 构建工具版本:22.0.1
项目文件:
activity_main.xml
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent"
android:layout_height="match_parent" android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:paddingBottom="@dimen/activity_vertical_margin" tools:context=".MainActivity"
android:id="@+id/">
<TextView android:text="@string/hello_world" android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</RelativeLayout>
build.gradle(项目:MyApplication)
apply plugin: 'com.android.application'
android {
compileSdkVersion 22
buildToolsVersion "22.0.1"
defaultConfig {
applicationId "com.example.abhinavmoudgil95.myapplication"
minSdkVersion 14
targetSdkVersion 22
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:22.1.1'
}
build.grade(模块:应用)
apply plugin: 'com.android.application'
android {
compileSdkVersion 22
buildToolsVersion "22.0.1"
defaultConfig {
applicationId "com.example.abhinavmoudgil95.myapplication"
minSdkVersion 14
targetSdkVersion 22
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:22.1.1'
}
我对 android 开发完全陌生。所以请尽量回答简单。
稍作修改:
您没有在 RelativeLayout
中的android:id="@+id/"
中定义 id
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent"
android:layout_height="match_parent" android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:paddingBottom="@dimen/activity_vertical_margin" tools:context=".MainActivity"
android:id="@+id/layout">
<TextView android:text="@string/hello_world" android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</RelativeLayout>
当您为 xml 中的任何 view
定义 android:id
preoperies 时,必须提供这样的唯一 ID,因此您不能像您在 ur 中所做的那样留下空白 ID xml.
删除这一行:
android:id="@+id/"
或
添加一些唯一的 ID 名称:
android:id="@+id/relativeLayout"