0

I have created empty map activity, added the KEY, and try to build but got this error: cant resolve symbol 'FragmentActivity'

I have tried adding: implementation 'com.android.support:support-v4:28.0.0' to the gradle as in other solutions, but still same error

package com.example.praycomp;

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);
    }

...
}



apply plugin: 'com.android.application'

android {
    compileSdkVersion 28
    defaultConfig {
        applicationId "com.example.praycomp"
        minSdkVersion 17
        targetSdkVersion 28
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation 'com.android.support:appcompat-v7:28.0.0'
    implementation 'com.google.android.gms:play-services-maps:17.0.0'
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'com.android.support.test:runner:1.0.2'
    androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
    implementation 'androidx.fragment:fragment:1.0.0'
    implementation 'com.android.support:support-v4:28.0.0'
}

and I have this in my gradle.properties:

android.useAndroidX=true
android.enableJetifier=true

I want to understand why I see this error and how to solve it

Atheel Massalha
  • 424
  • 1
  • 6
  • 18

1 Answers1

1

You're mixing Androidx dependencies with Android Support library ones. You have useAndroidX as true, so use Androidx dependencies.

Remove

implementation 'com.android.support:appcompat-v7:28.0.0'
implementation 'com.android.support:support-v4:28.0.0'

from your app/build.gradle and add

implementation 'androidx.appcompat:appcompat:1.1.0-beta01'

and then import FragmentActivity like below:

import androidx.fragment.app.FragmentActivity;
Vedprakash Wagh
  • 3,595
  • 3
  • 12
  • 33
  • thanks alot! this works so for understanding, from where now andorid studio ges the Fragment ? if I only added androidX.appcompact and not androidX.fragment – Atheel Massalha Jul 02 '19 at 17:33
  • when you're adding androidX fragment, you're only adding particular Fragment dependency. With appcompat you add everything. – Vedprakash Wagh Jul 02 '19 at 22:26
  • thanks, any tutorial that will help me understanding those relations between the gradle file and the dependencies ? what about 'com.android.support.test:runner:1.0.2', it also should be changed to androidX ? – Atheel Massalha Jul 03 '19 at 04:43
  • Instead of manually changing those dependencies one by one, use "Migrate to AndroidX" feature in Android Studio. I don't know exactly where that option is, but you can google how to migrate to androidx. – Vedprakash Wagh Jul 03 '19 at 06:56