错误:不兼容类型:应用程序无法转换为AnalyticsApplication.:Android Studio 2.3.2

错误:不兼容类型:应用程序无法转换为AnalyticsApplication.:Android Studio 2.3.2,android,android-application-class,Android,Android Application Class,我将Android Studio更新为2.3.2,之后gradle构建失败,出现以下错误: error: incompatible types: Application cannot be converted to AnalyticsApplication. 我试过搜索,但找不到任何相关信息 build.gradle文件: android { compileSdkVersion 25 buildToolsVersion "25.0.2" defaultConfig { app

我将Android Studio更新为2.3.2,之后gradle构建失败,出现以下错误:

error: incompatible types: Application cannot be converted to AnalyticsApplication.
我试过搜索,但找不到任何相关信息

build.gradle文件:

android {
  compileSdkVersion 25
  buildToolsVersion "25.0.2"

defaultConfig {
    applicationId "com.xxx.xxx"
    minSdkVersion 15
    targetSdkVersion 23
    versionCode 17
    versionName "1.6.7"
    multiDexEnabled true
}
我在这里出错了

        // Obtain the shared Tracker instance.
        AnalyticsApplication application = (AnalyticsApplication) getApplication();
        mTracker = application.getDefaultTracker();

        sharedPrefs = PreferenceManager
                .getDefaultSharedPreferences(context);
        sharedPrefsEditor = sharedPrefs.edit();

        defineFields();

    } catch (Exception e) {
        e.printStackTrace();
    }
AnalyticaApplication.java:

import android.app.Application;
import android.support.multidex.MultiDexApplication;

import com.google.android.gms.analytics.GoogleAnalytics;
import com.google.android.gms.analytics.Tracker;

 /**
 * This is a subclass of {@link Application} used to provide shared          objects for this app, such as the {@link Tracker}.*/
    public class AnalyticsApplication extends MultiDexApplication {
    private Tracker mTracker;

    /**
     * Gets the default {@link Tracker} for this {@link Application}.
     * @return tracker
     */
    synchronized public Tracker getDefaultTracker() {
    if (mTracker == null) {
        GoogleAnalytics analytics = GoogleAnalytics.getInstance(this);
        // To enable debug logging use: adb shell setprop log.tag.GAv4 DEBUG
        mTracker = analytics.newTracker(R.xml.global_tracker);
     }
        return mTracker;
    }
}

我看得出你用过

import android.support.multidex.MultiDexApplication;
正如您特别提到的将studio版本更新为2.3,我建议您看看

我不太确定,但这可能是你问题的解决方案,因为我自己在studio升级后也遇到了类似的问题。
希望它对您有所帮助。

使用构建、gradle文件和应用程序更新您的问题class@cricket_007请检查更新的问题。