0
votes

I'm coding Firebase in my app that has GoogleMaps. Firebase I have controlled, I get push-up, I subscribe themes, etc. but when I implement it I can't load the activity with the googleMaps xml. It crash. Without Firebase I have min-Sdk 11 and all okey but when I put Firebase I need 14 then it gives problems.

My app gradle:

""apply plugin: 'com.android.application'
apply plugin: 'com.google.gms.google-services'
//apply plugin: 'com.google.gms.google-services'
android {
    compileSdkVersion 26
   //buildToolsVersion '23.0.2'

    defaultConfig {
        applicationId "sdelatorre.turisxat"
        minSdkVersion 11
        targetSdkVersion 26
        versionCode 1
        versionName "1.0"
        multiDexEnabled true
    }
    buildTypes {
        release {
            minifyEnabled true
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
        debug {
            minifyEnabled false

        }
    }
}

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
   // implementation 'com.google.firebase:firebase-messaging:17.3.4'
    testImplementation 'junit:junit:4.12'


    implementation 'com.android.support:appcompat-v7:24.1.1'
    implementation 'com.android.support:design:24.1.1'
    implementation 'org.jsoup:jsoup:1.8.1'
    implementation 'com.android.support:recyclerview-v7:23.4.0'
    implementation 'com.google.android.gms:play-services:9.2.1'
    implementation 'com.google.android.gms:play-services-gcm:8.3.0'
    implementation 'com.android.support:multidex:1.0.3'

}""

So ...without Firebase app is running perfectly...When I put FIrebase I need to change to min-sdk =14 but then the map crash...

 ""<RelativeLayout
        xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:tools="http://schemas.android.com/tools"
        xmlns:app="http://schemas.android.com/apk/res-auto"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        >

        <fragment
            android:id="@+id/map"
            android:name="com.google.android.gms.maps.SupportMapFragment"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_alignParentStart="true"
            android:layout_alignParentTop="true"
            android:layout_marginStart="0dp"
            android:layout_marginTop="0dp"
            tools:context="sdelatorre.turisxat.Mapas"
            android:layout_alignParentLeft="true"
            android:layout_marginLeft="0dp" />

        <TextView
            android:id="@+id/cerca"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignBottom="@+id/map"
            android:layout_marginLeft="20dp"
            android:background="#ffffff"
            android:gravity="center_vertical|center_horizontal|center"
            android:textAppearance="?android:attr/textAppearanceLarge"
            android:textSize="@dimen/abc_text_size_large_material" />
    </RelativeLayout>""

I have tested the next xml and it crashes ....


    ""<?xml version="1.0" encoding="utf-8"?>
    <fragment xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:map="http://schemas.android.com/apk/res-auto"
        xmlns:tools="http://schemas.android.com/tools"
        android:id="@+id/map"
        android:name="com.google.android.gms.maps.SupportMapFragment"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        tools:context=".MapsActivity" />
    ""

My Log:

""2020-02-15 10:13:51.809 23903-23903/sdelatorre.turisxat I/atorre.turisxa: at void sdelatorre.turisxat.Mapas.onCreate(android.os.Bundle) (Mapas.java:65) 2020-02-15 10:13:51.813 23903-23903/sdelatorre.turisxat E/AndroidRuntime: FATAL EXCEPTION: main Process: sdelatorre.turisxat, PID: 23903 java.lang.RuntimeException: Unable to start activity ComponentInfo{sdelatorre.turisxat/sdelatorre.turisxat.Mapas}: android.view.InflateException: Binary XML file line #10: Binary XML file line #10: Error inflating class fragment at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2964) at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3099) at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:78) at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:108) at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:68) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1856) at android.os.Handler.dispatchMessage(Handler.java:106) at android.os.Looper.loop(Looper.java:228) at android.app.ActivityThread.main(ActivityThread.java:6734) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:911) Caused by: android.view.InflateException: Binary XML file line #10: Binary XML file line #10: Error inflating class fragment Caused by: android.view.InflateException: Binary XML file line #10: Error inflating class fragment Caused by: android.support.v4.app.Fragment$InstantiationException: Unable to instantiate fragment com.google.android.gms.maps.SupportMapFragment: calling Fragment constructor caused an exception at android.support.v4.app.Fragment.instantiate(Fragment.java:481) at android.support.v4.app.FragmentContainer.instantiate(FragmentContainer.java:33) at android.support.v4.app.FragmentManagerImpl.onCreateView(FragmentManager.java:3664) at android.support.v4.app.FragmentController.onCreateView(FragmentController.java:111) at android.support.v4.app.FragmentActivity.dispatchFragmentsOnCreateView(FragmentActivity.java:338) at android.support.v4.app.BaseFragmentActivityApi14.onCreateView(BaseFragmentActivityApi14.java:39) at android.support.v4.app.FragmentActivity.onCreateView(FragmentActivity.java:67) at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:791) at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:730) at android.view.LayoutInflater.rInflate(LayoutInflater.java:880) at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:841) at android.view.LayoutInflater.inflate(LayoutInflater.java:515) at android.view.LayoutInflater.inflate(LayoutInflater.java:423) at android.view.LayoutInflater.inflate(LayoutInflater.java:374) at com.android.internal.policy.PhoneWindow.setContentView(PhoneWindow.java:420) at android.app.Activity.setContentView(Activity.java:2771) at sdelatorre.turisxat.Mapas.onCreate(Mapas.java:65) at android.app.Activity.performCreate(Activity.java:7136) at android.app.Activity.performCreate(Activity.java:7127) at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1271) at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2944) at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3099) at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:78) at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:108) at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:68) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1856) at android.os.Handler.dispatchMessage(Handler.java:106) at android.os.Looper.loop(Looper.java:228) at android.app.ActivityThread.main(ActivityThread.java:6734) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:911) Caused by: java.lang.reflect.InvocationTargetException""

and my Mapas.java:

""
public class Mapas extends FragmentActivity implements OnMapReadyCallback{

        private GoogleMap mMap;

        LocationManager locationManager;
        String locationProvider;
        String tipo;
        double latitude,longitude;

        @Override
        protected void onPause() {
            super.onPause();
            stopService(new Intent(this, Localizacion.class));
        }

        @Override
        protected void onResume() {
            super.onResume();
            startService(new Intent(this, Localizacion.class));
           // getActivity().startService(new Intent(getActivity(), MyService.class));
           TextView t=(TextView) findViewById(R.id.cerca);
            t.setText("GPS");
        }

        @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_mapas);
            // 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);
            tipo=getIntent().getExtras().getString("parametro");
            LocalBroadcastManager.getInstance(this).registerReceiver(
                    new BroadcastReceiver() {
                        @Override
                        public void onReceive(Context context, Intent intent) {
                            latitude = intent.getDoubleExtra(Localizacion.EXTRA_LATITUDE, 0);
                            longitude = intent.getDoubleExtra(Localizacion.EXTRA_LONGITUDE, 0);
                            //textView.setText("Lat: " + latitude + ", Lng: " + longitude);
                            moverCamara(latitude,longitude);

                            if (tipo.equals("UNICO")){
                    marcadoresSoloMapa();
                            }else {
                                comprueba_mas_carca(latitude, longitude);
                            }
                        }
                    }, new IntentFilter(Localizacion.ACTION_LOCATION_BROADCAST)
            );
        }""

Thanks in advance...if you have any idea...

1
android:layout_alignBottom="@+id/map doesn't look right - shouldn't be adding the id here - get rid of +.Andy
I have changed it for : .. " <TextView android:id="@+id/cerca" android:layout_width="wrap_content" android:layout_height="wrap_content" />" The ERROR is the samesdelatorre

1 Answers

0
votes

Finally,I reviewed all code and I used the androidx library. I had the supportv4 but with androidx the app will run perfectly.

I changed all layouts of my app with the androidx components