我正在制作一个简单的 map 应用程序,但在运行它时,显示了我不明白的错误....
我的项目最小 SDK 是 android 2.2(Froyo) API 8,目标 SDK 是 android 4.4(kitkat) API 19,应用程序是用 Google API 2 rev 8 编译的......
我真的不知道为了让我的应用程序运行,min、target 和编译的 api 应该是什么组合....帮我找出正确的组合。
以下是我的 list 文件代码
<?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
我正在制作一个 map 应用程序,但在运行它时,上述错误显示在问题部分和控制台部分。
最佳答案
您的问题是您正在尝试实现 Google Maps API V1,可能使用 Google Maps API V2 key 。而且你做不到。
所以您应该做的是在您的代码中进行以下更改:
1. 删除:<uses-library android:name="com.google.android.maps"/>"
从您的 list 文件中,这是一个 V1 权限。
2. 如果您想支持 V8 API,那么您必须将您的 Activity 实现删除到 MapActivity
并将其更改为 FragmentActivity
.用于支持旧系统上的 fragment 。
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. 最后,您必须在 list 文件中添加一些人员:
添加这些权限:
<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 。
您还可以使用我就此主题编写的本指南来帮助您解决问题:
并检查生成 api key 的步骤并确保您没有遗漏任何东西:
关于java - 类型转换为 Dalvik 格式失败 : Unable to execute dex: java. nio.BufferOverflowException,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23063228/