• After 15+ years, we've made a big change: Android Forums is now Early Bird Club. Learn more here.

Apps How to enable Google Maps work in China?

ac4android

Well-Known Member
Nov 3, 2015
198
29
My apps were running well on a "Samsung Galaxy S5" in USA, using T-Mobile as my service provider.

Now. I am testing the same app on a "vivo v3ma" in China using China Mobile as my service provider. It is running Android 5.1 (Lollipop).

On the Chinese vivo, I have installed Play Store, Google Maps and Google Street View. On running G/Maps, it reported that GPS was not or cannot be turned on, and G/Maps downloaded and will use Google APIs to display maps.

G/Maps run well after that, it can display bilingual maps of Shanghai.

But when I run my app, it crashes when it tried to display the same Google maps. The console displays following NullPointerException error:
W/dalvikvm: threadid=1: thread exiting with uncaught exception (group=0xa4d30b20)
E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.swpwr.builders.swpwrassetlocation, PID: 2206
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.swpwr.builders.swpwrassetlocation/com.swpwr.builders.swpwrassetlocation.ShowMapsActivity}: java.lang.NullPointerException

at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2195)
debugger1.JPG

debugger2.JPG


Also, when I plug the vivo3ma into the laptop running A/Studio, the AVD Manager cannot see it. When I plug my Galaxy S5 in, the AVD Manager displays it prominently.
AVDmanager.JPG


Questions:
(1) What Google APIs do I need to import/compile into my app to display the G/Maps in China ?
(2) Why can't A/Studio's AVD screen see the vivo3ma phone ?


My build-gradle xml. Are there some other Google APIs that I have to include in the dependencies??
Code:
apply plugin: 'com.android.application'

android {
    compileSdkVersion 24
    buildToolsVersion "25.0.1"

    defaultConfig {
        applicationId "com.swpwr.builders.swpwrassetlocation"
        minSdkVersion 17
        targetSdkVersion 22
        versionCode 1
        versionName "1.0"
        // enable multi-dex support
        multiDexEnabled true
    }
    buildTypes {
        release {
            minifyEnabled true
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}
dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    testCompile 'junit:junit:4.12'
    compile 'com.android.support:appcompat-v7:24.2.1'
    compile 'com.android.support:design:24.2.1'
    compile 'com.android.support:support-v4:24.2.1'
    compile 'com.google.android.gms:play-services-appindexing:9.4.0'
    compile 'com.google.android.gms:play-services-maps:9.4.0'
    compile 'com.google.android.gms:play-services-ads:9.4.0'
    compile 'com.google.android.gms:play-services-identity:9.4.0'
    compile 'com.google.android.gms:play-services-gcm:9.4.0'
    compile 'com.google.android.gms:play-services-analytics:9.4.0'
    compile 'com.google.maps.android:android-maps-utils:0.4.+'
}

XML to show map
Code:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    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"
    app:layout_behavior="@string/appbar_scrolling_view_behavior"
    tools:context="com.swpwr.builders.swpwrassetlocation.ShowMapsActivity"
    tools:showIn="@layout/activity_show_maps">

    <fragment xmlns:android="http://schemas.android.com/apk/res/android"
        android:name="com.google.android.gms.maps.MapFragment"
        android:id="@+id/map"
        android:layout_width="match_parent"
        android:layout_height="match_parent"/>

    <TextView
        android:id="@+id/map_header"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/hello_world"/>

</RelativeLayout>

The activity code, I've hi-lited the line where the app crashed:
Code:
...
import android.app.Activity;
import android.net.Uri;
import android.os.Bundle;
import android.view.Menu;
import com.google.android.gms.appindexing.Action;
import com.google.android.gms.appindexing.AppIndex;
import com.google.android.gms.common.api.GoogleApiClient;
import com.google.android.gms.maps.CameraUpdate;
import com.google.android.gms.maps.CameraUpdateFactory;
import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.MapFragment;
import com.google.android.gms.maps.OnMapReadyCallback;
import com.google.android.gms.maps.model.BitmapDescriptorFactory;
import com.google.android.gms.maps.model.LatLng;
import com.google.android.gms.maps.model.Marker;
import com.google.android.gms.maps.model.MarkerOptions;

public class ShowMapsActivity extends Activity implements OnMapReadyCallback {

    private GoogleMap gMap;
    private MapFragment mapFragment;
    private LatLng depot;
    private LatLng current;
    private LatLng site;
    /**
     * ATTENTION: This was auto-generated to implement the App Indexing API.
     * See https://g.co/AppIndexing/AndroidStudio for more information.
     */
    private GoogleApiClient client;
    // adjust the zoom level of the map, from 1 to 16
    private int zoomLevel = 9;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        // grab the current latitude and longitude of the truck
        Bundle bundle = getIntent().getParcelableExtra("bundletag");
        depot = bundle.getParcelable("depotLatLng");
        site = bundle.getParcelable("siteLatLng");
        current = bundle.getParcelable("currentLatLng");
        //
        setContentView(R.layout.activity_show_maps);
        mapFragment = ((MapFragment) getFragmentManager().findFragmentById(R.id.map));
        mapFragment.getMapAsync(this);
        // This was auto-generated to implement the App Indexing API.
        // See https://g.co/AppIndexing/AndroidStudio for more information.
        client = new GoogleApiClient.Builder(this).addApi(AppIndex.API).build();
    }

    public void onMapReady(GoogleMap thisMap) {
        gMap = thisMap;

// etc lotsofcode...
...
A/Studio jump to this error message when it hit the above line of code.
D/dalvikvm: GC_FOR_ALLOC freed <1K, 3% free 7946K/8188K, paused 5ms, total 5ms
E/dalvikvm: Could not find class 'android.graphics.drawable.RippleDrawable', referenced from method android.support.v7.widget.AppCompatImageHelper.hasOverlappingRendering
W/dalvikvm: VFY: unable to resolve instanceof 177 (Landroid/graphics/drawable/RippleDrawable;) in Landroid/support/v7/widget/AppCompatImageHelper;
 
Last edited:
First thing, I'm not a developer so can't really answer your questions probably.

But I know Google Maps runs just fine on the Chinese version Oppo phones(the same company as Vivo) I've had. However when it's in China, it must use a VPN, otherwise Google Maps online is blocked by the GFW.
 
Last edited:
Upvote 0
Hi and thx for ur insight.

Yes, G/Maps run just find, I can also download and install Play Store etc. I also use VPN, which is not illegal according to web sites, it is only illegal if used for some purposes of which I am not interested in. By the way, they will be changing the rule in 2018.

It's my app that's not running in China, and I strongly suspect I need to download some Google APIs to use G/Maps. The phones here get their maps and GPS location from service provider like China Mobile.
 
Upvote 0
Does AnyOne find its solution?
Want to use my google services without VPN Connection.
My application working in different countries and for specifically in China I cannot change my google services.
Help me, If anyone got its solution.

Well you must have a VPN to use Google Services in China, otherwise they're blocked by the GFW, that's it.

If you're making an app that's intended for distribution and use in China, then you might need to use the equivalent services provided by, Baidu, Tencent, Alibaba, etc.

Some apps and games do have specific PRC versions, that may not be in Google Play. If your app depends on Google Services exclusively and it's only distributed by Google Play, then in theory nobody in China should be using it.
 
Last edited:
Upvote 0

BEST TECH IN 2023

We've been tracking upcoming products and ranking the best tech since 2007. Thanks for trusting our opinion: we get rewarded through affiliate links that earn us a commission and we invite you to learn more about us.

Smartphones