Retire v1 embedding compatibility from automatic multidex support (#100685)
This commit is contained in:
parent
1a072f9aee
commit
ead5b1c2f4
@ -25,25 +25,35 @@ File _getMultiDexApplicationFile(Directory projectDir) {
|
||||
void ensureMultiDexApplicationExists(final Directory projectDir) {
|
||||
final File applicationFile = _getMultiDexApplicationFile(projectDir);
|
||||
if (applicationFile.existsSync()) {
|
||||
return;
|
||||
// This checks for instances of legacy versions of this file. Legacy versions maintained
|
||||
// compatibility with v1 embedding by extending FlutterApplication. If we detect this,
|
||||
// we replace the file with the modern v2 embedding version.
|
||||
if (applicationFile.readAsStringSync().contains('android.app.Application;')) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
applicationFile.createSync(recursive: true);
|
||||
|
||||
final StringBuffer buffer = StringBuffer();
|
||||
buffer.write('''
|
||||
// Generated file.
|
||||
//
|
||||
// If you wish to remove Flutter's multidex support, delete this entire file.
|
||||
//
|
||||
// Modifications to this file should be done in a copy under a different name
|
||||
// as this file may be regenerated.
|
||||
|
||||
package io.flutter.app;
|
||||
|
||||
import android.app.Application;
|
||||
import android.content.Context;
|
||||
import androidx.annotation.CallSuper;
|
||||
import androidx.multidex.MultiDex;
|
||||
|
||||
/**
|
||||
* Extension of {@link io.flutter.app.FlutterApplication}, adding multidex support.
|
||||
* Extension of {@link android.app.Application}, adding multidex support.
|
||||
*/
|
||||
public class FlutterMultiDexApplication extends FlutterApplication {
|
||||
public class FlutterMultiDexApplication extends Application {
|
||||
@Override
|
||||
@CallSuper
|
||||
protected void attachBaseContext(Context base) {
|
||||
|
@ -14,7 +14,7 @@ import '../../src/common.dart';
|
||||
import '../../src/context.dart';
|
||||
|
||||
void main() {
|
||||
testUsingContext('ensureMultidexUtilsExists returns when exists', () async {
|
||||
testUsingContext('ensureMultidexUtilsExists patches file when invalid', () async {
|
||||
final Directory directory = globals.fs.currentDirectory;
|
||||
final File applicationFile = directory.childDirectory('android')
|
||||
.childDirectory('app')
|
||||
@ -32,7 +32,33 @@ void main() {
|
||||
ensureMultiDexApplicationExists(directory);
|
||||
|
||||
// File should remain untouched
|
||||
expect(applicationFile.readAsStringSync(), 'hello');
|
||||
expect(applicationFile.readAsStringSync(), '''
|
||||
// Generated file.
|
||||
//
|
||||
// If you wish to remove Flutter's multidex support, delete this entire file.
|
||||
//
|
||||
// Modifications to this file should be done in a copy under a different name
|
||||
// as this file may be regenerated.
|
||||
|
||||
package io.flutter.app;
|
||||
|
||||
import android.app.Application;
|
||||
import android.content.Context;
|
||||
import androidx.annotation.CallSuper;
|
||||
import androidx.multidex.MultiDex;
|
||||
|
||||
/**
|
||||
* Extension of {@link android.app.Application}, adding multidex support.
|
||||
*/
|
||||
public class FlutterMultiDexApplication extends Application {
|
||||
@Override
|
||||
@CallSuper
|
||||
protected void attachBaseContext(Context base) {
|
||||
super.attachBaseContext(base);
|
||||
MultiDex.install(this);
|
||||
}
|
||||
}
|
||||
''');
|
||||
}, overrides: <Type, Generator>{
|
||||
FileSystem: () => MemoryFileSystem.test(),
|
||||
ProcessManager: () => FakeProcessManager.any(),
|
||||
|
@ -298,18 +298,23 @@ class MultidexProject extends Project {
|
||||
|
||||
String get appMultidexApplication => r'''
|
||||
// Generated file.
|
||||
//
|
||||
// If you wish to remove Flutter's multidex support, delete this entire file.
|
||||
//
|
||||
// Modifications to this file should be done in a copy under a different name
|
||||
// as this file may be regenerated.
|
||||
|
||||
package io.flutter.app;
|
||||
|
||||
import android.app.Application;
|
||||
import android.content.Context;
|
||||
import androidx.annotation.CallSuper;
|
||||
import androidx.multidex.MultiDex;
|
||||
|
||||
/**
|
||||
* Extension of {@link io.flutter.app.FlutterApplication}, adding multidex support.
|
||||
* Extension of {@link android.app.Application}, adding multidex support.
|
||||
*/
|
||||
public class FlutterMultiDexApplication extends FlutterApplication {
|
||||
public class FlutterMultiDexApplication extends Application {
|
||||
@Override
|
||||
@CallSuper
|
||||
protected void attachBaseContext(Context base) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user