Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

breaking: only support androidx #1052

Merged
merged 3 commits into from
Apr 15, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 2 additions & 2 deletions bin/templates/cordova/lib/config/GradlePropertiesParser.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ class GradlePropertiesParser {
'org.gradle.jvmargs': '-Xmx2048m',

// Android X
'android.useAndroidX': 'false',
'android.enableJetifier': 'false'
'android.useAndroidX': 'true',
'android.enableJetifier': 'true'

// Shaves another 100ms, but produces a "try at own risk" warning. Not worth it (yet):
// 'org.gradle.parallel': 'true'
Expand Down
7 changes: 0 additions & 7 deletions bin/templates/cordova/lib/prepare.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@ module.exports.prepare = function (cordovaProject, options) {
const minSdkVersion = this._config.getPreference('android-minSdkVersion', 'android');
const maxSdkVersion = this._config.getPreference('android-maxSdkVersion', 'android');
const targetSdkVersion = this._config.getPreference('android-targetSdkVersion', 'android');
const androidXEnabled = this._config.getPreference('AndroidXEnabled', 'android');
const isGradlePluginKotlinEnabled = this._config.getPreference('GradlePluginKotlinEnabled', 'android');
const gradlePluginKotlinCodeStyle = this._config.getPreference('GradlePluginKotlinCodeStyle', 'android');

Expand All @@ -72,12 +71,6 @@ module.exports.prepare = function (cordovaProject, options) {
gradlePropertiesUserConfig['kotlin.code.style'] = gradlePluginKotlinCodeStyle || 'official';
}

// Both 'useAndroidX' and 'enableJetifier' are linked together.
if (androidXEnabled) {
gradlePropertiesUserConfig['android.useAndroidX'] = androidXEnabled;
gradlePropertiesUserConfig['android.enableJetifier'] = androidXEnabled;
}

const gradlePropertiesParser = new GradlePropertiesParser(this.locations.root);
gradlePropertiesParser.configure(gradlePropertiesUserConfig);

Expand Down
2 changes: 1 addition & 1 deletion bin/templates/project/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
<activity android:name="__ACTIVITY__"
android:label="@string/activity_name"
android:launchMode="singleTop"
android:theme="@android:style/Theme.DeviceDefault.NoActionBar"
android:theme="@style/Theme.AppCompat.NoActionBar"
android:windowSoftInputMode="adjustResize"
android:configChanges="orientation|keyboardHidden|keyboard|screenSize|locale|smallestScreenSize|screenLayout|uiMode">
<intent-filter android:label="@string/launcher_name">
Expand Down
1 change: 1 addition & 0 deletions bin/templates/project/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -339,6 +339,7 @@ android {

dependencies {
implementation fileTree(dir: 'libs', include: '*.jar')
implementation 'androidx.appcompat:appcompat:1.2.0'

if (cdvHelpers.getConfigPreference('GradlePluginKotlinEnabled', 'false').toBoolean()) {
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
Expand Down
4 changes: 4 additions & 0 deletions framework/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,10 @@ task sourcesJar(type: Jar) {
classifier = 'sources'
}

dependencies {
implementation 'androidx.appcompat:appcompat:1.2.0'
}

artifacts {
archives sourcesJar
}
Expand Down
6 changes: 3 additions & 3 deletions framework/src/org/apache/cordova/CordovaActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,13 @@ Licensed to the Apache Software Foundation (ASF) under one
import org.json.JSONException;
import org.json.JSONObject;

import android.app.Activity;
import android.app.AlertDialog;
import android.annotation.SuppressLint;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.res.Configuration;
import android.graphics.Color;
import android.media.AudioManager;
import android.os.Build;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
Expand All @@ -43,6 +41,8 @@ Licensed to the Apache Software Foundation (ASF) under one
import android.webkit.WebViewClient;
import android.widget.FrameLayout;

import androidx.appcompat.app.AppCompatActivity;

/**
* This class is the main Android activity that represents the Cordova
* application. It should be extended by the user to load the specific
Expand Down Expand Up @@ -74,7 +74,7 @@ Licensed to the Apache Software Foundation (ASF) under one
* deprecated in favor of the config.xml file.
*
*/
public class CordovaActivity extends Activity {
public class CordovaActivity extends AppCompatActivity {
public static String TAG = "CordovaActivity";

// The webview for our app
Expand Down
5 changes: 2 additions & 3 deletions framework/src/org/apache/cordova/CordovaInterface.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,10 @@ Licensed to the Apache Software Foundation (ASF) under one
*/
package org.apache.cordova;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;

import org.apache.cordova.CordovaPlugin;
import androidx.appcompat.app.AppCompatActivity;

import java.util.concurrent.ExecutorService;

Expand Down Expand Up @@ -56,7 +55,7 @@ public interface CordovaInterface {
*
* @return the Activity
*/
public abstract Activity getActivity();
public abstract AppCompatActivity getActivity();

/**
* Get the Android context.
Expand Down
13 changes: 7 additions & 6 deletions framework/src/org/apache/cordova/CordovaInterfaceImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,15 @@ Licensed to the Apache Software Foundation (ASF) under one
package org.apache.cordova;

import android.annotation.SuppressLint;
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.os.Build;
import android.os.Bundle;
import android.util.Pair;

import androidx.appcompat.app.AppCompatActivity;

import org.json.JSONException;
import org.json.JSONObject;

Expand All @@ -39,7 +40,7 @@ Licensed to the Apache Software Foundation (ASF) under one
*/
public class CordovaInterfaceImpl implements CordovaInterface {
private static final String TAG = "CordovaInterfaceImpl";
protected Activity activity;
protected AppCompatActivity activity;
protected ExecutorService threadPool;
protected PluginManager pluginManager;

Expand All @@ -51,11 +52,11 @@ public class CordovaInterfaceImpl implements CordovaInterface {
protected boolean activityWasDestroyed = false;
protected Bundle savedPluginState;

public CordovaInterfaceImpl(Activity activity) {
public CordovaInterfaceImpl(AppCompatActivity activity) {
this(activity, Executors.newCachedThreadPool());
}

public CordovaInterfaceImpl(Activity activity, ExecutorService threadPool) {
public CordovaInterfaceImpl(AppCompatActivity activity, ExecutorService threadPool) {
this.activity = activity;
this.threadPool = threadPool;
this.permissionResultCallbacks = new CallbackMap();
Expand All @@ -76,13 +77,13 @@ public void startActivityForResult(CordovaPlugin command, Intent intent, int req
public void setActivityResultCallback(CordovaPlugin plugin) {
// Cancel any previously pending activity.
if (activityResultCallback != null) {
activityResultCallback.onActivityResult(activityResultRequestCode, Activity.RESULT_CANCELED, null);
activityResultCallback.onActivityResult(activityResultRequestCode, AppCompatActivity.RESULT_CANCELED, null);
}
activityResultCallback = plugin;
}

@Override
public Activity getActivity() {
public AppCompatActivity getActivity() {
return activity;
}

Expand Down
60 changes: 0 additions & 60 deletions test/android/README.md

This file was deleted.

1 change: 0 additions & 1 deletion test/android/app/.gitignore

This file was deleted.

61 changes: 0 additions & 61 deletions test/android/app/build.gradle

This file was deleted.

36 changes: 0 additions & 36 deletions test/android/app/proguard-rules.pro

This file was deleted.