我想将Google Maps Android API V2放在我的项目中,但我遇到了问题。
的AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.****.android.****"
android:versionCode="1"
android:versionName="1.0">
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="16"/>
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES"/>
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme"
android:uiOptions="splitActionBarWhenNarrow">
<activity
android:name="com.****.android.****.LoginActivity"
android:label="@string/app_name"
android:windowSoftInputMode="adjustResize|stateVisible">
<intent-filter >
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".fragmentmodule.AppMainTabActivity"
android:label="activity_main"/>
<activity
android:name=".PDFActivity"
android:label="activity_pdf"/>
<meta-data
android:name="com.google.android.maps.v2.API_KEY"
android:value="AIzaSyBfD***********QaNXISLpWaku"/>
</application>
</manifest>
的build.gradle
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.5.+'
}
}
apply plugin: 'android'
dependencies {
compile fileTree(dir: 'libs', include: '*.jar')
compile 'com.google.android.gms:play-services:3.1.36'
}
android {
compileSdkVersion 17
buildToolsVersion "17.0.0"
defaultConfig {
minSdkVersion 8
targetSdkVersion 16
}
}
myactivity.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="35dp"
android:layout_gravity="left|center_vertical"
android:layout_marginTop="10dp"
android:gravity="center_horizontal">
<Button
style="?android:attr/buttonStyleSmall"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:text="Note"
android:id="@+id/details_button_note"/>
<Button
style="?android:attr/buttonStyleSmall"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:text="Localisation"
android:id="@+id/details_button_location"/>
<Button
style="?android:attr/buttonStyleSmall"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:text="Mail"
android:id="@+id/details_button_mail"/>
<Button
style="?android:attr/buttonStyleSmall"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:text="Favori"
android:id="@+id/details_button_favori"/>
</LinearLayout>
<LinearLayout
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Organisme"
android:id="@+id/details_textView_organisme"
android:layout_gravity="left|center_vertical"
android:layout_marginTop="10dp"
android:textColor="@color/blueEmp"
android:textSize="14dp"/>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="left|center_vertical">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Date d'expiration :"
android:id="@+id/details_textViewBVF_date"
android:layout_gravity="center_horizontal|top"
android:textColor="#000000"
android:textSize="12dp"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="30/10/88 à 3h00"
android:id="@+id/details_textView_date"
android:layout_gravity="center_horizontal|bottom"
android:layout_marginLeft="7dp"
android:textColor="#000000"
android:textStyle="bold"
android:textSize="12dp"/>
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="left|center_vertical"
android:id="@+id/linearLayout">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Departement :"
android:id="@+id/details_textViewBF_dpt"
android:layout_gravity="center_horizontal|top"
android:textColor="@color/gris_emp"
android:textSize="10dp"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="75"
android:id="@+id/details_textView_dpt"
android:layout_gravity="center_horizontal|bottom"
android:layout_marginLeft="7dp"
android:textColor="@color/gris_emp"
android:textStyle="bold"
android:textSize="10dp"/>
</LinearLayout>
</LinearLayout>
<FrameLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:clickable="false">
<fragment
android:id="@+id/map"
android:layout_width="match_parent"
android:layout_height="match_parent"
class="com.google.android.gms.maps.MapFragment"/> <!-- This line doesn't works -->
<WebView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id="@+id/details_webview"
android:layout_gravity="center"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:layout_marginTop="10dp"/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Ouvrir le PDF"
android:id="@+id/details_button_pdf"
android:layout_gravity="center"
android:minWidth="200dp"
android:minHeight="100dp"/>
<EditText
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="@+id/details_edittext_note"
android:layout_gravity="center_horizontal|top"
android:layout_marginTop="20dp"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"/>
</FrameLayout>
</LinearLayout>
发生错误
Gradle: Error while executing dx command
Gradle: UNEXPECTED TOP-LEVEL EXCEPTION:
Gradle: java.lang.IllegalArgumentException: already added: Landroid/support/v4/app/ActivityCompatHoneycomb;
Gradle: at com.android.dx.dex.file.ClassDefsSection.add(ClassDefsSection.java:123)
Gradle: at com.android.dx.dex.file.DexFile.add(DexFile.java:163)
Gradle: at com.android.dx.command.dexer.Main.processClass(Main.java:490)
Gradle: 1 error; aborting
Gradle: Execution failed for task ':****:dexDebug'.
有人知道我为什么会遇到这个问题吗?
答案 0 :(得分:0)
请参阅,您也支持Pre-Honeycomb版本。你的清单说8-16。但你的片段上写着“class =”com.google.android.gms.maps.MapFragment“
将其更改为
<fragment android:id="@+id/mapFrag"
class="com.google.android.gms.maps.SupportMapFragment"
android:layout_width="match_parent"
android:layout_weight="match_parent"/>