调试器未进入MainActivity

时间:2019-05-08 15:00:37

标签: android android-studio

我遇到了奇怪的问题,白屏和调试器没有进入MainActivity。它进入App类,但不会在MainActivity中触发onCreate。

但是,如果我在没有调试的情况下启动我的应用程序-只需运行该应用程序或构建该应用程序-它将进入MainActivity的要求。我找不到我的应用程序中的任何特定内容,也找不到任何可能的信息

这是清单:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.something.something">

    <application
        android:name=".App"
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher_new"
        android:label="@string/app_name"
        android:largeHeap="true"
        android:roundIcon="@drawable/ic_launcher"
        android:theme="@style/AppTheme">
        <activity
            android:name=".MainActivity"
            android:screenOrientation="portrait"
            android:windowSoftInputMode="adjustPan"
            android:label="@string/app_name"
            android:theme="@style/AppTheme.NoActionBar">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>
    <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
    <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
    <uses-permission android:name="com.android.vending.BILLING" />
    <uses-permission android:name="android.permission.CALL_PHONE" />
    <uses-permission android:name="android.permission.INTERNET" />
</manifest>

这是应用程序:

public class App extends MultiDexApplication {

    private static Api api;
    private static Retrofit retrofit;

    @Override
    public void onCreate() {
        super.onCreate();
        initRetrofit();
        initGlobalVars();
    }

    private static void initRetrofit() {
        if (retrofit == null) {
            HttpLoggingInterceptor logging = new HttpLoggingInterceptor(new
                                                                                HttpLoggingInterceptor.Logger() {
                                                                                    @Override public void log(String message) {
                                                                                        Log.d("MyLog", "message: " + message);
                                                                                    }
                                                                                });
            logging.setLevel(HttpLoggingInterceptor.Level.BODY);
            final OkHttpClient okHttpClient = new OkHttpClient.Builder()
                    .connectTimeout(20, TimeUnit.SECONDS)
                    .writeTimeout(50, TimeUnit.SECONDS)
                    .readTimeout(50, TimeUnit.SECONDS)
                    .addInterceptor(logging)
                    .build();
            retrofit = new Retrofit.Builder()
                    .baseUrl(Setup.URL)
                    .addConverterFactory(ScalarsConverterFactory.create())
                    .client(okHttpClient)
                    .build();
            api = retrofit.create(Api.class);
        }
    }

    private void initGlobalVars(){
        GlobalVariableKeeper.INSTANCE.init(this);
    }

    public static Api getApi() {
        return api;
    }

    public static Retrofit getRetrofit(){
        return retrofit;
    }
}

和gradle

apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'

android {
    compileSdkVersion 28
    defaultConfig {
        applicationId "com.something.something"
        minSdkVersion 21
        targetSdkVersion 28
        versionCode 27
        versionName "0.35"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
        multiDexEnabled true
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation 'com.android.support:appcompat-v7:27.1.1'
    implementation 'com.google.code.gson:gson:2.8.2'
    implementation 'com.android.support.constraint:constraint-layout:1.1.2'
    implementation 'com.android.support:design:27.1.1'
    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 "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
    implementation 'de.hdodenhof:circleimageview:2.2.0'
    implementation 'com.google.android.gms:play-services:12.0.1'
    implementation 'com.android.support:multidex:1.0.3'
    implementation 'com.android.billingclient:billing:1.0'
    implementation 'com.squareup.retrofit2:retrofit:2.1.0'
    implementation 'com.squareup.retrofit2:converter-gson:2.1.0'
    implementation 'com.squareup.retrofit2:converter-scalars:2.1.0'
    implementation 'com.squareup.okhttp3:logging-interceptor:3.6.0'
}
repositories {
    mavenCentral()
}

0 个答案:

没有答案