简体   繁体   English

Google地图无法在发布模式下运行,但在调试模式下可以正常运行

[英]Google maps not working in release mode but working fine in debug mode

Google maps activity isn't working on release mode but working fine on Debug mode. Google Maps活动在发布模式下不起作用,但在调试模式下工作得很好。

Tried everything on stack overflow related to my query but its not working. 尝试了所有与我的查询相关的堆栈溢出问题,但无法正常工作。

I also copied SHA1 Key from cmd prompt using "keytool -list -v -keystore mystore.keystore" and pasted it in the google console but still its not working. 我还使用“ keytool -list -v -keystore mystore.keystore”从cmd提示符下复制了SHA1 Key,并将其粘贴到了Google控制台中,但仍然无法正常工作。

In debug mode everything is working good.. I have also given run time permission for android marshmallow and above. 在调试模式下,一切正常。.我还为Android棉花糖及更高版本授予了运行时权限。

Point to note: I have used mapView in place of fragments.. I have also tried with map fragments but still the same issue. 需要注意的是:我使用mapView代替了片段。.我也尝试过使用地图片段,但是仍然是同样的问题。

activity_maps.xml activity_maps.xml

<com.google.android.gms.maps.MapView
    android:id="@+id/map"
    android:layout_width="match_parent"
    android:layout_height="match_parent" />

You can see the difference here: 您可以在这里看到区别:

In debug mode , In release mode 在调试模式下在释放模式下

Gradles: 等级:

implementation 'com.google.android.gms:play-services-maps:16.1.0'
implementation 'com.google.android.gms:play-services-location:16.0.0'

AndroidManifest.xml AndroidManifest.xml

<uses-permission android:name="android.permission.ACCESS_WIFI_STATE"/> 
<uses-permission android:name="android.permission.CHANGE_NETWORK_STATE"/> 
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/> 
<uses-permission android:name="android.permission.INTERNET" /> 
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" /> 
<uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES" /> 
<permission android:name="com.example.mapsact.permission.MAPS_RECEIVE" android:protectionLevel="signature" /> 
<uses-permission android:name="com.example.mapsact.permission.MAPS_RECEIVE" />

MapsActivity.java MapsActivity.java

MapView mMapView;
GoogleMap mMap;
LocationManager location;

@Override
public void onResume() {
    super.onResume();

    try {
        locationManager = (LocationManager) this.getSystemService(Context.LOCATION_SERVICE);
        locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 20, 1, (android.location.LocationListener) this);
    } catch (SecurityException e) {
        e.printStackTrace();
    }
    mMapView.onResume();
    //ActivityCompat.requestPermissions(this, new String[]{Manifest.permission.ACCESS_FINE_LOCATION}, 1);
}

@Override
public void onLocationChanged(Location location) {

    // Getting latitude of the current location
    latitude = location.getLatitude();
    // Getting longitude of the current location
    longitude = location.getLongitude();
    // Creating a LatLng object for the current location
    LatLng latLng = new LatLng(latitude, longitude);
    //now = mMap.addMarker(new MarkerOptions().position(latLng).title("Location").snippet("Current"));
    // Showing the current location in Google Map
    mMap.moveCamera(CameraUpdateFactory.newLatLng(latLng));
    mMap.animateCamera(CameraUpdateFactory.zoomTo(15.0f));

    if(isNetworkConnected()) {
        JSONObject jsonObject = new JSONObject();
        try {
            jsonObject.put("mobile", mobile);
            jsonObject.put("lati", latitude);
            jsonObject.put("longi", longitude);
            SendLoc sendloc = new SendLoc();
            sendloc.execute(jsonObject.toString());
        } catch (JSONException e) {
            e.printStackTrace();
        }
    }
    else {
        Toast.makeText(this,"No Internet Connectivity",Toast.LENGTH_LONG).show();
    }
}
    public void onMapReady(GoogleMap googleMap) {
    mMap = googleMap;
    mMap.animateCamera(CameraUpdateFactory.zoomTo(15.0f));
    mMap.setMyLocationEnabled(true);
}

Just a guess but in release mode I think you need the key defined for maps this is from the manifest 只是一个猜测,但在发布模式下,我认为您需要为清单定义的密钥来自清单

<!--
         The API key for Google Maps-based APIs is defined as a 
          string resource.
         (See the file "res/values/google_maps_api.xml").
         Note that the API key is linked to the encryption key 
          used to sign the APK.
         You need a different API key for each encryption key, 
          including the release key that is used to
         sign the APK for publishing.
         You can define the keys for the debug and release 
          targets in src/debug/ and src/release/. 
    -->

I was also facing the same problem since last few days and it took me around 2-3 days to figure out the problem. 自最近几天以来,我还面临着同样的问题,并且花了大约2-3天的时间才弄清问题所在。 You need to add your API key at 2 places one in app/src/debug/res/values/google_maps_api.xml and other in app/src/release/res/values/google_maps_api.xml. 您需要在2个位置添加API密钥,一个在app / src / debug / res / values / google_maps_api.xml中,另一个在app / src / release / res / values / google_maps_api.xml中。

You can find the release/google_maps_api.xml in the project mode not in the Android/application mode. 您可以在项目模式下(而非Android /应用程序模式下)找到release / google_maps_api.xml。

您可以在此处查看可提供release / google_maps_api.xml的图片。

暂无
暂无

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

相关问题 谷歌地图在发布apk中显示空白屏幕,在调试模式下工作正常 - Google Maps displaying blank screen in release apk, working fine in debug mode Android应用程式在侦错模式下运作良好,但在发布模式下当机 - Android app working fine in debug mode but crashing in release mode Firebase电话身份验证在调试模式下可以正常工作,但该应用在发行时崩溃 - Firebase phone authentication is working fine in debug mode but the app is crashing in release react-native-geolocation-service 按预期在调试模式下工作正常但在发布模式下不工作 - react-native-geolocation-service working perfectly fine in debug mode as expected but not working in release mode 具有释放模式的黑屏,应用程序无法启动。 在调试模式下工作正常 - Blank screen with release mode, app does not start. Working fine in debug mode Flutter apk 在发布模式和调试模式下运行良好,但内置 apk 不工作? - Flutter apk running fine in release mode and debug mode but built apk not working? 缓存的 notwork 图像在调试模式下工作正常,但在发布模式下显示占位符 flutter,请问有什么解决方案吗? - cached notwork image is working fine in debug mode but showing place holder in release mode flutter ,any solution please? Android minifyEnabled true在调试和发布模式下不起作用 - Android minifyEnabled true is not working in Debug and Release mode java.lang.VerifyError:验证器拒绝类。 代码在调试模式下工作正常,但在发布模式下不会抛出此错误 - java.lang.VerifyError: Verifier rejected class. Code working fine in debug mode, but not throwing this error in release mode Firebase Google身份验证在发布模式下不起作用 - Firebase google authentication not working in release mode
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM