2014-04-14 28 views
2

我想提出一個簡單的地圖應用程序,但上運行它,會顯示錯誤,我不明白....類型轉換的Dalvik格式失敗:無法執行DEX:java.nio.BufferOverflowException

我項目min SDK是android 2.2(Froyo)API 8,目標SDK是android 4.4(kitkat)API 19,app是用Google API 2 rev 8編譯的.....

我真的不知道應該是什麼min,target和編譯apis的組合,以便使我的應用程序能夠運行....幫助我以正確的組合。

以下是我的清單文件代碼

<?xml version="1.0" encoding="utf-8"?> 
<manifest xmlns:android="http://schemas.android.com/apk/res/android" 
package="com.example.margallahillhikedroid" 
android:versionCode="1" 
android:versionName="1.0" > 

<uses-sdk 
    android:minSdkVersion="8" 
    android:targetSdkVersion="19" /> 
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/> 
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/> 
<uses-permission android:name="android.permission.INTERNET"/> 

<application 
    android:allowBackup="true" 
    android:icon="@drawable/ic_launcher" 
    android:label="@string/app_name" 
    android:theme="@style/AppTheme" > 
    <uses-library android:name="com.google.android.maps"/>" 
    <activity 
     android:name="com.example.margallahillhikedroid.MainActivity" 
     android:label="@string/app_name" > 
     <intent-filter> 
      <action android:name="android.intent.action.MAIN" /> 

      <category android:name="android.intent.category.LAUNCHER" /> 
     </intent-filter> 
    </activity> 
</application> 

</manifest> 

//以下是主要的Java源

//包com.example.margallahillhikedroid;

import com.google.android.maps.MapActivity; 
import com.google.android.maps.MapView; 

import android.os.Bundle; 

import android.view.Menu; 

public class MainActivity extends MapActivity { 
MapView map; 
@Override 
protected void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.activity_main); 
    map=(MapView)findViewById(R.id.mymap); 
} 

@Override 
public boolean onCreateOptionsMenu(Menu menu) { 
    // Inflate the menu; this adds items to the action bar if it is present. 
    getMenuInflater().inflate(R.menu.main, menu); 
    return true; 
} 

@Override 
protected boolean isRouteDisplayed() { 
    // TODO Auto-generated method stub 
    return false; 
} 

} 

以下是運行在以下顯示控制檯部錯誤應用的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:paddingBottom="@dimen/activity_vertical_margin" 
android:paddingLeft="@dimen/activity_horizontal_margin" 
android:paddingRight="@dimen/activity_horizontal_margin" 
android:paddingTop="@dimen/activity_vertical_margin" 
tools:context=".MainActivity" > 
<com.google.android.maps.MapView 
     android:id="@+id/mymap" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:apiKey="AIzaSyBcTxeirTSzthVlMal5JDDC-SK-Mw7s_CE"/> 

</RelativeLayout> 

;

[2014-04-14 07:37:14 - MargallahillHikedroid] Dx 
trouble writing output: already prepared 
[2014-04-14 07:37:14 - Dex Loader] Unable to execute dex:  java.nio.BufferOverflowException. Check the Eclipse log for stack trace. 
[2014-04-14 07:37:14 - MargallahillHikedroid] Conversion to Dalvik format failed: Unable to execute dex: java.nio.BufferOverflowException. Check the Eclipse log for stack trace. 
的問題部分下面的錯誤

顯示

Description Resource Path Location Type 
Conversion to Dalvik format failed: Unable to execute dex: java.nio.BufferOverflowException. Check the Eclipse log for stack trace. MargallahillHikedroid  Unknown Android Packaging Problem 

我想提出一個地圖應用,但在運行上述提到它的錯誤顯示在問題部分以及控制檯部分。

回答

1

你的問題是,你正在試圖實現谷歌地圖API V1,可能使用Google Maps API V2密鑰。而你不能這樣做。

所以,你應該做的是讓你的代碼以下更改:

刪除:<uses-library android:name="com.google.android.maps"/>" 從你的清單文件,這是一個V1權限。

2.如果你想支持V8 API,那麼你必須刪除你的活動實施MapActivity並將其更改爲FragmentActivity。用於支持舊系統的片段。

3。改變從你的XML佈局文件:

<com.google.android.maps.MapView 
    android:id="@+id/mymap" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:apiKey="AIzaSyBcTxeirTSzthVlMal5JDDC-SK-Mw7s_CE"/> 

要這樣:

<fragment 
    android:name="com.google.android.gms.maps.SupportMapFragment" 
    xmlns:map="http://schemas.android.com/apk/res-auto" 
    android:id="@+id/map" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" /> 

4.最後,你必須添加一些工作人員在清單文件:

添加這些權限:

<permission android:name="your.application.package.permission.MAPS_RECEIVE" 
android:protectionLevel="signature"/> 
<uses-permission android:name="your.application.package.permission.MAPS_RECEIVE"/> 
<uses-permission android:name="android.permission.INTERNET" /> 
<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" /> 

<uses-feature 
android:glEsVersion="0x00020000" 
android:required="true"/> 

更改your.applicat ion.package到您的實際應用程序包名稱。

並添加這些:

<meta-data 
android:name="com.google.android.maps.v2.API_KEY" 
android:value="Your Google Maps API V2 Key" /> 

<meta-data 
android:name="com.google.android.gms.version" 
android:value="@integer/google_play_services_version" /> 
application蜂房下

您也可以使用這個指南,我就這個話題寫來幫助你:

Google Maps API V2

,再三產生API關鍵的步驟,並確保你沒有錯過任何事情:

Google Maps API V2 Key

+0

你的兩個鏈接不打開! – user3431536

+0

我的博客服務器出現了一些問題,應該現在就去吧:) –

0

它有時適用於Eclipse。你只需要關閉Eclipse,重新啓動它,清理你的項目,刷新它,然後重試...它應該做的伎倆...;)

+0

人來上你的建議已經給它一個球,但不起作用!!!!我需要一個正確的答案和我的項目的錯誤解決方案... – user3431536

+0

這就是我處理這個問題的方式,當它發生時......它適用於我...然後,也許它不適合你和某人有另一個答案...祝你好運。 ;) –

-1

你需要實現谷歌地圖V2。可能是以下行清單中的用途庫導致該問題android:name="com.google.android.maps"

+0

我正在使用Google Map v2 – user3431536

+0

請問我可以告訴我apis的組合有什麼問題嗎?如果min sdk或者target sdk中有錯誤或者使用api/version編譯 – user3431536

+0

告訴我應該改變什麼在提到的行清單 – user3431536

0

的分SDK forvmap v2是11請換that.And嘗試

+0

如何更改它現在過程plz – user3431536

+0

你可以找到聲明min sdk在manifest.xml文件那裏你可以改變最小sdk版本 –

相關問題