简体   繁体   English

Android 2.3.4中的Google Map在AVD和真实设备上均显示灰色框

[英]Google Map in Android 2.3.4 shows gray box on both AVD and real device

I'm trying to show a simple google map on my real Samsung device where Android version is 2.3.4. 我正在尝试在Android版本为2.3.4的真实三星设备上显示一个简单的Google地图。

  • got my SHA1 key 得到了我的SHA1密钥
  • got my API key from google 从Google获得了我的API密钥

Here is my manifest file: 这是我的清单文件:

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

    <uses-sdk
        android:minSdkVersion="8"
        android:targetSdkVersion="18" />

    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
    <uses-permission android:name="android.permission.INTERNET" />
    <uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES" />
    <!-- External storage for caching. -->
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
    <!-- My Location -->
    <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
    <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
    <!-- Maps API needs OpenGL ES 2.0. -->
    <uses-feature
        android:glEsVersion="0x00020000"
        android:required="true" />

    <application
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >

        <meta-data
            android:name="com.google.android.maps.v2.API_KEY"
            android:value="AIzaSyBq8ATEI-DmBtso1T13S_DGfiT7cBgEav8" />

        <activity
            android:name="com.neighbourhoodlocator.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>

Here is my main.xml file: 这是我的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" >

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/hello_world" />
    <fragment
        android:id="@+id/map"     
        android:layout_width="match_parent"        
        android:layout_height="match_parent"        
class="com.google.android.gms.maps.SupportMapFragment"/>

</RelativeLayout>

Here is my Mainactivity.java file: 这是我的Mainactivity.java文件:

public class MainActivity extends FragmentActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
    }

    @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;
    }

}

Now the issue I'm having when I launch it on the real device, it doesn't crash, nor it throws any exception (No "Invalid Authorization" either); 现在,当我在真实设备上启动它时遇到的问题是,它不会崩溃,也不会引发任何异常(也没有“无效授权”); only thing I can see on the screen is a blank (gray box) with "+" and "-" button. 我只能在屏幕上看到的是带有“ +”和“-”按钮的空白(灰色框)。 I've tried Activity instead of FragmentActivity , application crashed. 我尝试使用Activity而不是FragmentActivity ,应用程序崩溃了。

I checked the logcat trace: 我检查了logcat跟踪:

10-12 23:14:34.989: W/dalvikvm(15055): VFY: unable to resolve instance field 28
10-12 23:14:35.119: W/dalvikvm(15055): Unable to resolve superclass of Lmaps/p/w; (743)
10-12 23:14:35.119: W/dalvikvm(15055): Link of class 'Lmaps/p/w;' failed
10-12 23:14:35.119: W/dalvikvm(15055): Unable to resolve superclass of Lmaps/ap/as; (6267)
10-12 23:14:35.119: W/dalvikvm(15055): Link of class 'Lmaps/ap/as;' failed
10-12 23:14:35.139: W/dalvikvm(15055): Unable to resolve superclass of Lmaps/af/k; (5294)
10-12 23:14:35.139: W/dalvikvm(15055): Link of class 'Lmaps/af/k;' failed
10-12 23:14:35.139: E/dalvikvm(15055): Could not find class 'maps.af.k', referenced from method maps.ag.an.a
10-12 23:14:35.139: W/dalvikvm(15055): VFY: unable to resolve new-instance 5139 (Lmaps/af/k;) in Lmaps/ag/an;

I added the google-play-services_lib appropriately. 我适当地添加了google-play-services_lib and also added the android-support-v4.jar is also in "Android private libraries". 并且还添加了android-support-v4.jar也在“ Android私有库”中。

Notice that the project build target is: Google APIs 4.2.2 and the android version in my Samsung phone is: 2.3.4 请注意,项目构建目标为:Google APIs 4.2.2,而我的三星手机中的android版本为:2.3.4

I've been trying last couple of days, I also tried in the emulator, same thing is happening. 最近几天我一直在尝试,我也在模拟器中尝试过,同样的事情正在发生。 Please help me to solve the issue. 请帮我解决问题。 Thanks. 谢谢。

I had a similar problem.. I have solved it. 我有一个类似的问题..我已经解决了。 Android emulators aren't working. Android模拟器无法正常工作。 You should work your app on your phone. 您应该在手机上使用您的应用程序。 When exporting your project, your sha1 is changing. 导出项目时,sha1正在更改。 You must copy that sha1 and make a new API-KEY in google api console. 您必须复制该sha1并在Google API控制台中创建新的API密钥。 (don't forget the change manifest file). (不要忘记更改清单文件)。 After uploading your phone, it works.. 上传手机后,它就可以工作了。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM