制作简单的 Google Android Maps API v2 项目时 Android Studio 中的编译错误 [英] Compilation error in Android Studio When making a simple Google Android Maps API v2 project
问题描述
最近我迁移到基于 IntelliJ 的新 Android Studio IDE
Recently I migrated to the New Android Studio IDE based on IntelliJ
我遵循的指南是:
如何在 Android Studio 中创建使用 Google Maps Api v2 的 Android 应用程序?(用于导入所需的 Google Play 服务和支持库到android studio)
Android Studio 正确检测到所有库,我没有收到任何未找到库错误".该项目显示无错误.然后当我尝试编译它时,我收到了这个错误.
All the libraries were properly detected by Android Studio and i didn't get any 'library not found errors'. The project was shown error free. Then when i tried to compile it i got this error.
Gradle:
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':AID-AmritaInfoDesk:compileDebug'.
> Compilation failed; see the compiler error output for details.
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.
Could not execute build using Gradle distribution 'http://services.gradle.org/distributions/gradle-1.6-bin.zip'.
这是我的explorer.java文件
package com.aid.explorer;
import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.SupportMapFragment;
import com.google.android.gms.maps.model.LatLng;
import com.google.android.gms.maps.model.MarkerOptions;
import android.os.Bundle;
import android.support.v4.app.FragmentActivity;
public class explorer extends FragmentActivity {
private GoogleMap mMap;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.explorer);
setUpMapIfNeeded();
}
@Override
protected void onResume() {
super.onResume();
setUpMapIfNeeded();
}
private void setUpMapIfNeeded() {
// Do a null check to confirm that we have not already instantiated the map.
if (mMap == null) {
// Try to obtain the map from the SupportMapFragment.
mMap = ((SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map))
.getMap();
// Check if we were successful in obtaining the map.
if (mMap != null) {
setUpMap();
}
}
}
private void setUpMap() {
mMap.addMarker(new MarkerOptions().position(new LatLng(0, 0)).title("Marker"));
}
}
这是我的explorer.xml文件
<?xml version="1.0" encoding="utf-8"?>
<fragment xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/map"
android:layout_width="match_parent"
android:layout_height="match_parent"
class="com.google.android.gms.maps.SupportMapFragment"/>
我想知道出了什么问题.任何帮助将非常感激
I would like to know what went wrong. any help would be greatly appreciated
推荐答案
我按照相同的说明进行操作,只是我要创建一个新项目.在项目结构下,我删除了 Android-Gradle facet 并能够成功构建.可以选择更新 gradle 构建文件并将 Android-Gradle 方面添加到播放服务库.
I was following the same instructions except I was creating a new project. Under the project structure I removed the Android-Gradle facet and was able to build successfully. Optionally one can update the gradle build files and add the Android-Gradle facet to the play services library.
注意:我更改了 Google Play 服务目录的名称.
NOTE: I changed the name of Google Play Services directory.
build.gradle
用于 Google Play 服务库.
build.gradle
for Google Play Services library.
apply plugin: 'android-library'
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.4'
}
}
dependencies {
compile files('libs/android-support-v4.jar')
compile files('google-play-services.jar')
}
android {
compileSdkVersion 17
buildToolsVersion '17.0.0'
sourceSets {
main {
manifest.srcFile 'AndroidManifest.xml'
java.srcDirs = ['src']
resources.srcDirs = ['src']
aild.srcDirs = ['src']
renderscript.srcDirs = ['src']
res.srcDirs = ['res']
assets.srcDirs = ['assets']
}
}
}
build.gradle
用于测试应用.
buildscript {
repositories {
maven { url 'http://repo1.maven.org/maven2' }
}
dependencies {
classpath 'com.android.tools.build:gradle:0.4'
}
}
apply plugin: 'android'
dependencies {
compile files('libs/android-support-v4.jar')
compile project(':lib-google-play-services')
compile files('../lib-google-play-services/libs/google-play-services.jar')
}
android {
compileSdkVersion 17
buildToolsVersion "17.0.0"
defaultConfig {
minSdkVersion 11
targetSdkVersion 16
}
}
这篇关于制作简单的 Google Android Maps API v2 项目时 Android Studio 中的编译错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!