我的Android应用程序出现了gradle构建错误。我的代码结构如下:
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 sync。我不确定这是否与同一问题有关,但是,在DefaultMap.java中,我收到错误:
cannot resolve symbol, 'R'
我该怎么做才能解决这个问题?该项目甚至不会正确构建,我相信这是一个简单的错误。我没有真正编辑任何东西,因为在xml方面从android-studio实例化默认项目,除了在androidmanifest中添加notitlebar的行,而我在build.gradle中尝试更改的唯一一件事是增加sdk从21到23.有人有什么建议吗?我尝试过重建,关闭项目并重新导入,使缓存失效并重新启动,这是我找到的主要内容,可以找到遇到同样问题的以前的人。
答案 0 :(得分:0)
尝试制作项目并清理项目,然后重新构建
答案 1 :(得分:0)
当您的某个XML文件损坏时,通常会发生R错误。有时不明显!
1)尝试在R.java
DefaultMap.java
2)Clean Project -> Sync Project with Gradle Files
如果这不起作用,请查看R.java
导入导致问题的原因。确保导入所需的R class
引用您所需的引用。