当我在动态模块上使用WebView时,Android App bundle> App将崩溃

时间:2019-10-23 12:24:19

标签: android app-bundle

如果我在动态模块上使用WebView而不在基本模块中使用WebView以及使用任何资源时。例如:R.string.xx,应用程序将崩溃。并且例外是有趣的“找不到资源”。但是,如果我不使用webview,则该应用程序将正常运行。 经过更多测试。我发现如果我在基本模块中使用Webview,它不会崩溃。

代码:

apply plugin: 'com.android.application'

android {
    compileSdkVersion 29
    buildToolsVersion "29.0.1"


    defaultConfig {
        applicationId "com.moly.hooyee.prank.monster"
        minSdkVersion 15
        targetSdkVersion 29
        versionCode 1
        versionName "1.0"

        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"

    }

    bundle {
        language {
            enableSplit = false
        }
        density {
            enableSplit = false
        }
        abi {
            enableSplit = true
        }
    }

    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
        }
    }

    dynamicFeatures = [":dynamic_feature"]
}

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])

    api 'androidx.appcompat:appcompat:1.1.0'
    api 'androidx.constraintlayout:constraintlayout:1.1.3'
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'androidx.test:runner:1.2.0'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
    api 'com.google.code.gson:gson:2.8.5'
    api "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
    api 'com.google.android.play:core:1.6.3'
}

MainActivity

package com.example.gson;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Toast;
import androidx.appcompat.app.AppCompatActivity;
import com.google.android.play.core.splitinstall.SplitInstallManager;
import com.google.android.play.core.splitinstall.SplitInstallManagerFactory;
import com.google.android.play.core.splitinstall.SplitInstallRequest;
import com.google.android.play.core.tasks.OnCompleteListener;
import com.google.android.play.core.tasks.OnSuccessListener;
import com.google.android.play.core.tasks.Task;

public class MainActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        findViewById(R.id.tv_next).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent("bundle.dji.demo");
                startActivity(intent);
            }
        });

        SplitInstallManager splitInstallManager = SplitInstallManagerFactory.create(this);

        SplitInstallRequest request = SplitInstallRequest.newBuilder()
                .addModule("dynamic_feature")
                .build();

        splitInstallManager
                // Submits the request to install the module through the
                // asynchronous startInstall() task. Your app needs to be
                // in the foreground to submit the request.
                .startInstall(request)
                .addOnSuccessListener(new OnSuccessListener<Integer>() {
                    @Override
                    public void onSuccess(Integer integer) {
                        Toast.makeText(MainActivity.this, "success", Toast.LENGTH_SHORT).show();
                    }
                })
                .addOnCompleteListener(new OnCompleteListener<Integer>() {
                    @Override
                    public void onComplete(Task<Integer> task) {
                        Toast.makeText(MainActivity.this, "OnCompleteListener", Toast.LENGTH_SHORT).show();

                    }
                });
        }
}

动态模块,TestActivity:

package com.example.dynamic_feature;

import android.content.Context;
import android.util.Log;
import android.view.View;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import com.google.android.play.core.splitcompat.SplitCompat;

public class TestActivity extends AppCompatActivity {

    @Override
    protected void attachBaseContext(Context newBase) {
        super.attachBaseContext(newBase);
        SplitCompat.install(this);
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_test);
        findViewById(R.id.tv_test).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Log.e("hooyee", getString(R.string.hooyee_test));
            }
        });
    }
}

<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout
        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"
        tools:context=".TestActivity">

    <WebView android:layout_width="match_parent" android:layout_height="match_parent"></WebView>

    <TextView android:id="@+id/tv_test"
              android:text="testing"
              app:layout_constraintLeft_toLeftOf="parent"
              app:layout_constraintRight_toRightOf="parent"
              app:layout_constraintTop_toTopOf="parent"
              app:layout_constraintBottom_toBottomOf="parent"
              android:layout_width="wrap_content"
              android:layout_height="wrap_content"/>
</androidx.constraintlayout.widget.ConstraintLayout>

1 个答案:

答案 0 :(得分:1)

似乎是appcompat问题。 (https://issuetracker.google.com/issues/141351441

您应该使用androidx appcompat 1.0.2版本。