Demo android app using Google map api is crashing

CanniZarro :

I have been learning android app development for a while and I am suffering from this annoying bug where my app crashes as I run it on my device (Mi a1, android 9, API 28). I haven't made any changes in the original code just entered my api in the appropriate places.

AndroidManifest.xml

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

    <!--
         The ACCESS_COARSE/FINE_LOCATION permissions are not required to use
         Google Maps Android API v2, but you must specify either coarse or fine
         location permissions for the 'MyLocation' functionality.
    -->
    <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />

    <application
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:roundIcon="@mipmap/ic_launcher_round"
        android:supportsRtl="true"
        android:theme="@style/AppTheme">

        <!--
             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/.
        -->
        <meta-data
            android:name="com.google.android.geo.API_KEY"
            android:value="@string/google_maps_key" />

        <activity
            android:name=".MapsActivity"
            android:label="@string/title_activity_maps">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>

</manifest>

google_maps_api.xml

<resources>
<!--
TODO: Before you run your application, you need a Google Maps API key.

To get one, follow this link, follow the directions and press "Create" at the end:

https://console.developers.google.com/flows/enableapi?apiid=maps_android_backend&keyType=CLIENT_SIDE_ANDROID&r=D0:2E:31:27:4F:07:82:C0:F9:CD:5F:14:70:FF:28:CB:29:85:5A:CE%3Bcom.example.googlemapdemo

You can also add your credentials to an existing key, using these values:

Package name:
D0:2E:31:27:4F:07:82:C0:F9:CD:5F:14:70:FF:28:CB:29:85:5A:CE

SHA-1 certificate fingerprint:
D0:2E:31:27:4F:07:82:C0:F9:CD:5F:14:70:FF:28:CB:29:85:5A:CE

Alternatively, follow the directions here:
https://developers.google.com/maps/documentation/android/start#get-key

Once you have your key (it starts with "AIza"), replace the "google_maps_key"
string in this file.
-->
<string name="google_maps_key" templateMergeStrategy="preserve" translatable="false">AIzaSyDHi-e0aEeDxZbspTt5m5ydO0Kv5gxdd_8</string>

MapsActivity.java

package com.example.googlemapdemo;

import android.support.v4.app.FragmentActivity;
import android.os.Bundle;

import com.google.android.gms.maps.CameraUpdateFactory;
import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.OnMapReadyCallback;
import com.google.android.gms.maps.SupportMapFragment;
import com.google.android.gms.maps.model.LatLng;
import com.google.android.gms.maps.model.MarkerOptions;

public class MapsActivity extends FragmentActivity implements OnMapReadyCallback {

    private GoogleMap mMap;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_maps);
        // Obtain the SupportMapFragment and get notified when the map is ready to be used.
        SupportMapFragment mapFragment = (SupportMapFragment) getSupportFragmentManager()
                .findFragmentById(R.id.map);
        mapFragment.getMapAsync(this);
    }


    /**
     * Manipulates the map once available.
     * This callback is triggered when the map is ready to be used.
     * This is where we can add markers or lines, add listeners or move the camera. In this case,
     * we just add a marker near Sydney, Australia.
     * If Google Play services is not installed on the device, the user will be prompted to install
     * it inside the SupportMapFragment. This method will only be triggered once the user has
     * installed Google Play services and returned to the app.
     */
    @Override
    public void onMapReady(GoogleMap googleMap) {
        mMap = googleMap;

        // Add a marker in Sydney and move the camera
        LatLng sydney = new LatLng(-34, 151);
        mMap.addMarker(new MarkerOptions().position(sydney).title("Marker in Sydney"));
        mMap.moveCamera(CameraUpdateFactory.newLatLng(sydney));
    }
}

Error Message :

 E/AndroidRuntime: FATAL EXCEPTION: Thread-6
    Process: com.example.googlemapdemo, PID: 26667
    java.lang.NoClassDefFoundError: Failed resolution of: Lorg/apache/http/ProtocolVersion;
        at fb.b(:com.google.android.gms.dynamite_mapsdynamite@[email protected] (100408-231259764):3)
        at fa.a(:com.google.android.gms.dynamite_mapsdynamite@[email protected] (100408-231259764):3)
        at fc.a(:com.google.android.gms.dynamite_mapsdynamite@[email protected] (100408-231259764):15)
        at com.google.maps.api.android.lib6.drd.al.a(:com.google.android.gms.dynamite_mapsdynamite@[email protected] (100408-231259764):6)
        at ee.a(:com.google.android.gms.dynamite_mapsdynamite@[email protected] (100408-231259764):23)
        at ee.run(:com.google.android.gms.dynamite_mapsdynamite@[email protected] (100408-231259764):8)
     Caused by: java.lang.ClassNotFoundException: Didn't find class "org.apache.http.ProtocolVersion" on path: DexPathList[[zip file "/data/user_de/0/com.google.android.gms/app_chimera/m/000000bc/MapsDynamite.apk"],nativeLibraryDirectories=[/data/user_de/0/com.google.android.gms/app_chimera/m/000000bc/MapsDynamite.apk!/lib/arm64-v8a, /system/lib64, /system/vendor/lib64]]
        at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:134)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:379)
        at ad.loadClass(:com.google.android.gms.dynamite_dynamiteloader@[email protected] (100408-231259764):4)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:312)
        at fb.b(:com.google.android.gms.dynamite_mapsdynamite@[email protected] (100408-231259764):3) 
        at fa.a(:com.google.android.gms.dynamite_mapsdynamite@[email protected] (100408-231259764):3) 
        at fc.a(:com.google.android.gms.dynamite_mapsdynamite@[email protected] (100408-231259764):15) 
        at com.google.maps.api.android.lib6.drd.al.a(:com.google.android.gms.dynamite_mapsdynamite@[email protected] (100408-231259764):6) 
        at ee.a(:com.google.android.gms.dynamite_mapsdynamite@[email protected] (100408-231259764):23) 
        at ee.run(:com.google.android.gms.dynamite_mapsdynamite@[email protected] (100408-231259764):8) 

Please help.

Erik :

The LogCat have the error,

classnotfoundexception: Didn't find class "org.apache.http.ProtocolVersion"

Searching on that error show many result like this belov, try this, this might solve the error, add this to your Androidmanifest.xml

 <application
             ....
             >
             ...
          <uses-library android:name="org.apache.http.legacy" 
           android:required="false"/>
             ....
<application/>

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=145980&siteId=1