问题描述
我的Android应用程式出现了gradle build错误。 我的代码具有以下结构:
app
manifests
java
package.myApp
ApplicationTest.java
package.myApp.interfaces
map
DefaultMap.java
sidelists
welcomescreen
res
layout
mipmap
values
以下AndroidManifest.xml:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="package.myApp" >
<!--
The ACCESS_COARSE/FINE_LOCATION permissions are not required to use
Google Maps Android API v2, but you must specify either coarse or fine
location permissions for the 'MyLocation' functionality.
-->
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<!--
The API key for Google Maps-based APIs is defined as a string resource.
(See the file "res/values/google_maps_api.xml").
Note that the API key is linked to the encryption key used to sign the APK.
You need a different API key for each encryption key, including the release key that is used to
sign the APK for publishing.
You can define the keys for the debug and release targets in src/debug/ and src/release/.
-->
<meta-data
android:name="com.google.android.geo.API_KEY"
android:value="@string/google_maps_key" />
<activity
android:name=".interfaces.map.DefaultMap"
android:label="@string/title_activity_map__default">
android:theme="@android:style/Theme.NoTitleBar">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
以及模块的以下build.gradle:app:
apply plugin: 'com.android.application'
android {
compileSdkVersion 23
buildToolsVersion '23.0.1'
defaultConfig {
applicationId "oose2017.place2b"
minSdkVersion 15
targetSdkVersion 15
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:23.0.1'
compile 'com.google.android.gms:play-services:8.1.0'
}
由于某种原因,该项目似乎在构建问题。 在底部的后台任务中,通知显示了最近15分钟的“ gradle build running”,并且似乎挂断了(请注意,此操作是在8分钟前开始的,现在是5:55):
5:46:43 PM Gradle sync started
5:47:05 PM Gradle sync completed
5:47:06 PM Executing tasks: [:app:generateDebugSources, :app:generateDebugAndroidTestSources, :app:compileDebugSources, :app:compileDebugAndroidTestSources]
表示gradle同步已在该行上方完成后显示的最新行。 我不确定这是否与相同的问题有关,但是,在DefaultMap.java中,我收到此错误:
cannot resolve symbol, 'R'
我该怎么做才能解决这个问题? 该项目甚至无法正确构建,我相信这是一个简单的错误。 自从xml实例化android-studio的默认项目以来,我没有真正编辑任何东西,除了在androidmanifest中添加了notitlebar的行外,我唯一尝试在build.gradle中更改的就是增加sdk从21到23。有人有什么建议吗? 我尝试重建,关闭项目并重新导入,使缓存无效并重新启动,这是我搜索以前遇到相同问题的人的主要内容。
1楼
尝试制作项目并清理项目,然后再次重建
2楼
当您的XML文件之一损坏时,通常会发生R错误。 有时不明显!
1)尝试在DefaultMap.java
导入R.java
2) Clean Project -> Sync Project with Gradle Files
如果那不起作用,请查看是什么原因导致R.java
导入问题。
确保导入所需的R class
, R class
引用所需的R class
。