【问题标题】:Type Conversion to Dalvik format failed: Unable to execute dex: java.nio.BufferOverflowException类型转换为 Dalvik 格式失败:无法执行 dex:java.nio.BufferOverflowException
【发布时间】:2014-04-14 14:48:37
【问题描述】:

我正在制作一个简单的地图应用程序,但在运行它时,会显示我不明白的错误......

我的项目 min SDK 是 android 2.2(Froyo) API 8 ,目标 SDK 是 android 4.4(kitkat) API 19 并且应用程序是使用 Google API 2 rev 8 编译的.....

我真的不知道 min、target 和已编译 api 的组合应该是什么才能使我的应用程序运行 ....帮我找出正确的组合。

以下是我的清单文件代码

<?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

我正在制作地图应用程序,但在运行它时,上述错误会显示在问题部分和控制台部分中。

【问题讨论】:

    标签: java android google-maps syntax google-maps-android-api-2


    【解决方案1】:

    您的问题是您正在尝试实现 Google Maps API V1,可能使用 Google Maps API V2 密钥。而那是你做不到的。

    所以你应该做的是在你的代码中进行以下更改:

    1. 删除:&lt;uses-library android:name="com.google.android.maps"/&gt;" 从您的清单文件中,这是 V1 权限。

    2. 如果您想支持 V8 API,那么您必须将您的 Activity 的实现删除为 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.application.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 hive 下。

    您还可以使用我就该主题撰写的本指南来帮助您:

    Google Maps API V2

    并检查生成 api 密钥的步骤,并确保您没有遗漏任何事情:

    Google Maps API V2 Key

    【讨论】:

    • 我的博客服务器出了点问题,现在应该可以了 :)
    【解决方案2】:

    它有时会出现在 Eclipse 中。你只需要关闭 Eclipse,重新启动它,清理你的项目,刷新它,然后重试......它应该可以解决问题...... ;)

    【讨论】:

    • 男人来吧,你的建议已经给了它一个镜头,但那不起作用!!!!我需要一个正确的答案和我的项目的错误解决方案......
    • 这就是我处理这个问题的方式,当它发生时......它对我有用......然后,也许它对你不起作用,有人有另一个答案......祝你好运. ;)
    【解决方案3】:

    vmap v2 的 min sdk 是 11,请改成那个。然后试试

    【讨论】:

    • 现在如何更改它?procedure plz
    • 你可以在 manifest.xml 文件中找到 min sdk 的声明,你可以更改 min sdk 版本
    【解决方案4】:

    您需要实施 Google Map V2。可能是以下行导致清单使用库中的问题android:name="com.google.android.maps"

    【讨论】:

    • 我正在使用谷歌地图 v2
    • 能否请您告诉我 api 的组合有什么问题?比如 min sdk 或 target sdk 是否有错误或使用 api /version 编译
    • 告诉我应该对上述清单行进行哪些更改
    • 我已经检查了链接,但告诉我您是如何发现我没有使用 Google Map api V2 的?
    猜你喜欢
    • 1970-01-01
    • 2013-03-05
    • 1970-01-01
    • 2011-02-10
    • 2012-10-12
    • 2011-08-22
    • 1970-01-01
    • 2011-09-12
    • 1970-01-01
    相关资源
    最近更新 更多