Migrating to Android Studio 3 from 2.3

print
Bind to BindView


dependencies {
    compile 'com.google.dagger:dagger:2.0'
    annotationProcessor 'com.google.dagger:dagger-compiler:2.0'
}
buildscript {
    repositories {
      mavenCentral()
    }
    dependencies {
        // replace with the current version of the Android plugin
        classpath 'com.android.tools.build:gradle:1.3.0'
        // the latest version of the android-apt plugin
        classpath 'com.neenbedankt.gradle.plugins:android-apt:1.8'
    }
}
buildscript { repositories { jcenter() } dependencies { classpath 'com.neenbedankt.gradle.plugins:android-apt:1.8' } } apply plugin: 'com.neenbedankt.android-apt' dependencies { apt 'com.bluelinelabs:logansquare-compiler:1.3.6' compile 'com.bluelinelabs:logansquare:1.3.6' }

compile 'com.jakewharton:butterknife:8.8.1'
annotationProcessor 'com.jakewharton:butterknife-compiler:8.8.1'

The android-apt plugin has been deprecated.
Check here for the migration guide:

As of the Android Gradle plugin version 2.2, all functionality that was previously provided by android-apt is now available in the Android plugin.

You can remove android-apt by following the migration guide to get the equivalent functionalities.

The important parts from the migration guide:

  • Make sure you are on the Android Gradle 2.2 plugin or newer.
  • Remove the android-apt plugin from your build scripts
  • Change all aptandroidTestApt and testApt dependencies to their new format:
dependencies {
   compile 'com.google.dagger:dagger:2.0'
   annotationProcessor 'com.google.dagger:dagger-compiler:2.0'
}
apply plugin: 'com.android.application' apply plugin: 'com.neenbedankt.android-apt'

https://maps-apis.googleblog.com/2016/06/marker-zindex-and-more-come-to-google.html

getMapAsync() now required

In December 2014 we deprecated getMap() in favor of getMapAsync(). From this release onwards, you’ll need to use getMapAsync() in order to compile your apps. Note that existing apps in the wild on your users’ devices won’t be impacted by this change as the getMap() method still exists within the Google Play Services APK that is delivered to Android devices.

If you haven’t already done so, follow these steps:

Here’s a sample fragment using the deprecated getMap(), with a fictitious doStuff() method that would implement the fragment’s initial logic:

import android.os.Bundle;
 import android.support.v4.app.FragmentActivity;
 import com.google.android.gms.maps.GoogleMap;
 import com.google.android.gms.maps.SupportMapFragment;

 public class MainActivity extends FragmentActivity {

     private GoogleMap mMap;

     @Override
     public void onCreate(Bundle savedInstanceState) {
         super.onCreate(savedInstanceState);
         setContentView(R.layout.main);
         mMap = ((SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map)).getMap();
         doStuff();
     }

 }

The above however was error prone, since getMap() could potentially return null. Here’s the same sample using getMapAsync():

import android.os.Bundle;
 import android.support.v4.app.FragmentActivity;
 import com.google.android.gms.maps.GoogleMap;
 import com.google.android.gms.maps.OnMapReadyCallback;
 import com.google.android.gms.maps.SupportMapFragment;

 public class MainActivity extends FragmentActivity implements OnMapReadyCallback {

     private GoogleMap mMap;

     @Override
     public void onCreate(Bundle savedInstanceState) {
         super.onCreate(savedInstanceState);
         setContentView(R.layout.main);
         ((SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map)).getMapAsync(this);
     }

     @Override
     public void onMapReady(GoogleMap map) {
         mMap = map;
         doStuff();
     }

 }

You can see we now implement the OnMapReadyCallback interface which defines the onMapReady() method, which will be called when the GoogleMap instance is ready. We’ve also moved the call to the fictitious doStuff() method into onMapReady(), since this is where we now want to start the fragment’s initial logic.

A big thank you to Android developers everywhere for using the Google Maps Android API and submitting feedback via the issue tracker.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.