我一直在寻找过去3天的解决方案,但我无法找到解决问题的方法。 当我在我的设备上运行我的应用程序时,使用谷歌地图api v2,显示一条消息,我必须更新谷歌服务。我按照谷歌开发人员的每一步,和另一个教程,没有。这里是我的代码和日志猫...如果有人有解决方案,请帮助我。
清单xml:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.maps2"
android:versionCode="1"
android:versionName="1.0" >
<permission
android:name="com.example.maps2.permission.MAPS_RECEIVE"
android:protectionLevel="signature"/>
<uses-permission android:name="com.example.maps2.permission.MAPS_RECEIVE"/>
<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"/>
<uses-feature
android:glEsVersion="0x00020000"
android:required="true"/>
<uses-sdk
android:minSdkVersion="17"
android:targetSdkVersion="17" />
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name="com.example.maps2.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>
<meta-data
android:name="com.google.android.maps.v2.API_KEY"
android:value="AIzaSyDJWkuzL3moJzGH4JcLJXQa9_q1vG7Q3Xc"/>
<meta-data
android:name="com.google.android.gms.version"
android:value="@integer/google_play_services_version" />
</application>
布局xml:
<LinearLayout 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" >
<fragment
class="com.google.android.gms.maps.SupportMapFragment"
android:id="@+id/map"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:name="com.google.android.gms.maps.SupportMapFragment"/>
</LinearLayout>
MainActivity:
import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.SupportMapFragment;
import android.os.Bundle;
import android.support.v4.app.FragmentActivity;
public class MainActivity extends FragmentActivity {
private GoogleMap mMap;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
SupportMapFragment fm = (SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map);
mMap = fm.getMap();
}
}
logcat的:
11-04 16:13:21.921: E/Trace(27005): error opening trace file: No such file or directory (2)
11-04 16:13:22.761: I/dalvikvm(27005): Could not find method android.os.UserManager.getApplicationRestrictions, referenced from method xg.b
11-04 16:13:22.761: W/dalvikvm(27005): VFY: unable to resolve virtual method 3765: Landroid/os/UserManager;.getApplicationRestrictions (Ljava/lang/String;)Landroid/os/Bundle;
11-04 16:13:22.761: D/dalvikvm(27005): VFY: replacing opcode 0x6e at 0x0012
11-04 16:13:22.761: I/dalvikvm(27005): Could not find method android.accounts.AccountManager.getAccountsByTypeForPackage, referenced from method xg.c
11-04 16:13:22.761: W/dalvikvm(27005): VFY: unable to resolve virtual method 2421: Landroid/accounts/AccountManager;.getAccountsByTypeForPackage (Ljava/lang/String;Ljava/lang/String;)[Landroid/accounts/Account;
11-04 16:13:22.761: D/dalvikvm(27005): VFY: replacing opcode 0x6e at 0x000c
11-04 16:13:23.762: I/PeopleDatabaseHelper(27005): cleanUpNonGplusAccounts done.
11-04 16:13:24.253: D/dalvikvm(27005): Trying to load lib /data/app-lib/com.google.android.gms-1/libAppDataSearch.so 0x40d82670
11-04 16:13:24.263: D/dalvikvm(27005): Added shared lib /data/app-lib/com.google.android.gms-1/libAppDataSearch.so 0x40d82670
11-04 16:13:24.263: D/dalvikvm(27005): No JNI_OnLoad found in /data/app-lib/com.google.android.gms-1/libAppDataSearch.so 0x40d82670, skipping init
11-04 16:13:24.263: D/Icing(27005): Init last flush num docs 159 last docstore size 41216
11-04 16:13:24.273: D/Icing(27005): Docid map file has data, scanning...
11-04 16:13:24.283: D/Icing(27005): Scanning /data/data/com.google.android.gms/files/AppDataSearch/main/cur/ds.docids found 160 documents, last docstore location 41216
11-04 16:13:24.283: D/Icing(27005): File /data/data/com.google.android.gms/files/AppDataSearch/main/cur/ds.perdocdata contains 160 records of size 6
11-04 16:13:24.323: D/Icing(27005): Corpus scoring data inited successfully num corpora 2
11-04 16:13:24.323: D/Icing(27005): Init docstore ok num docs 160 bytes 41472
11-04 16:13:25.434: V/Icing(27005): Lite index crc computed in 0.092ms
11-04 16:13:25.434: V/Icing(27005): Lite index init ok in 122.498ms
11-04 16:13:25.434: D/Icing(27005): Lite index recovered docid (158, 159]
11-04 16:13:25.434: V/Icing(27005): Warming lite-index took 0.031ms
11-04 16:13:25.434: V/Icing(27005): Warming lexicon took 0.122ms
11-04 16:13:25.434: V/Icing(27005): Warming display mappings took 0.031ms
11-04 16:13:25.434: D/Icing(27005): Init index ok num docs 160
11-04 16:13:25.434: D/Icing(27005): Init done
11-04 16:13:33.322: E/Trace(27293): error opening trace file: No such file or directory (2)
11-04 16:13:33.582: D/PackageAddedReceiver(27293): package added com.example.maps2
11-04 16:13:34.633: I/dalvikvm(27293): Could not find method android.os.UserManager.getApplicationRestrictions, referenced from method xg.b
11-04 16:13:34.633: W/dalvikvm(27293): VFY: unable to resolve virtual method 3765: Landroid/os/UserManager;.getApplicationRestrictions (Ljava/lang/String;)Landroid/os/Bundle;
11-04 16:13:34.633: D/dalvikvm(27293): VFY: replacing opcode 0x6e at 0x0012
11-04 16:13:34.743: I/dalvikvm(27293): Could not find method android.accounts.AccountManager.getAccountsByTypeForPackage, referenced from method xg.c
11-04 16:13:34.743: W/dalvikvm(27293): VFY: unable to resolve virtual method 2421: Landroid/accounts/AccountManager;.getAccountsByTypeForPackage (Ljava/lang/String;Ljava/lang/String;)[Landroid/accounts/Account;
11-04 16:13:34.743: D/dalvikvm(27293): VFY: replacing opcode 0x6e at 0x000c
11-04 16:13:35.554: I/PeopleDatabaseHelper(27293): cleanUpNonGplusAccounts done.
11-04 16:13:36.565: D/dalvikvm(27293): Trying to load lib /data/app-lib/com.google.android.gms-1/libAppDataSearch.so 0x40d851d8
11-04 16:13:36.965: D/dalvikvm(27293): Added shared lib /data/app-lib/com.google.android.gms-1/libAppDataSearch.so 0x40d851d8
11-04 16:13:36.965: D/dalvikvm(27293): No JNI_OnLoad found in /data/app-lib/com.google.android.gms-1/libAppDataSearch.so 0x40d851d8, skipping init
11-04 16:13:36.965: D/Icing(27293): Init last flush num docs 159 last docstore size 41216
11-04 16:13:36.965: D/Icing(27293): Docid map file has data, scanning...
11-04 16:13:36.975: D/Icing(27293): Scanning /data/data/com.google.android.gms/files/AppDataSearch/main/cur/ds.docids found 160 documents, last docstore location 41216
11-04 16:13:36.975: D/Icing(27293): File /data/data/com.google.android.gms/files/AppDataSearch/main/cur/ds.perdocdata contains 160 records of size 6
11-04 16:13:37.025: D/Icing(27293): Corpus scoring data inited successfully num corpora 2
11-04 16:13:37.025: D/Icing(27293): Init docstore ok num docs 160 bytes 41472
11-04 16:13:37.596: I/Recovery(27293): Received: Intent { act=com.google.android.gms.INITIALIZE flg=0x10 pkg=com.google.android.gms cmp=com.google.android.gms/.auth.be.recovery.AccountRecoveryBackgroundService$Receiver }
11-04 16:13:38.457: I/Recovery(27293): Received: Intent { act=com.google.android.gms.INITIALIZE flg=0x10 pkg=com.google.android.gms cmp=com.google.android.gms/.auth.be.recovery.AccountRecoveryBackgroundService$Receiver }
11-04 16:13:38.717: V/Icing(27293): Lite index crc computed in 0.122ms
11-04 16:13:38.727: V/Icing(27293): Lite index init ok in 152.679ms
11-04 16:13:38.727: D/Icing(27293): Lite index recovered docid (158, 159]
11-04 16:13:38.727: V/Icing(27293): Warming lite-index took 0.031ms
11-04 16:13:38.737: V/Icing(27293): Warming lexicon took 6.592ms
11-04 16:13:38.747: V/Icing(27293): Warming display mappings took 7.050ms
11-04 16:13:38.747: D/Icing(27293): Init index ok num docs 160
11-04 16:13:38.747: D/Icing(27293): Init done
请在您的设备上测试该应用,并告诉我您的设备中是否显示此消息。
答案 0 :(得分:2)
请参阅此处,只需使用清单文件中的密钥更改api密钥,然后按照以下步骤操作: 并确保您的google_play_services_lib项目仅存在于项目的工作空间中。
清单文件:
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="18" />
<uses-feature
android:glEsVersion="0x00020000"
android:required="true" />
<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" >
<activity
android:name="com.geeklabs.map.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>
<meta-data
android:name="com.google.android.maps.v2.API_KEY"
android:value="replace with your API key"/>
</application>
</manifest>
MainActivity.java:
package com.geeklabs.map;
import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
public class MainActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
}
activity_main.xml中:
<?xml version="1.0" encoding="utf-8"?>
<fragment xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/map"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:name="com.google.android.gms.maps.MapFragment"/>
得到这个后告诉我。
答案 1 :(得分:0)
您是否正在调用不可用的方法?你的踪迹说“无法找到方法android.os.UserManager.getApplicationRestrictions,从方法xg.b中引用”。
我们可以在文档here中看到该方法可以从API lvl 18获得,并且由于您尝试在4.2.2设备(API级别17)上运行该方法,这可能是原因崩溃......