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

feat(android): Enable AndroidX and use AndroidX dependencies #2045

Merged
merged 32 commits into from
Feb 18, 2020

Conversation

priyankpat
Copy link
Contributor

Fixes Issue #1937

@wf9a5m75
Copy link
Contributor

wf9a5m75 commented Oct 17, 2019

Should be accepted ASAP.

@priyankpat
Copy link
Contributor Author

priyankpat commented Oct 17, 2019

It's planned for 2.0.0 Milestone but I noticed it being a roadblock for lots of devs including myself. Having said that, it might make or break some of the projects depending on the plugins installed (Mainly Cordova plugins). I'd suggest forking and installing @capacitor/android locally as a temporary measure until official release.

These are the Cordova plugins that I am currently using without any issue.

cordova-background-geolocation (3.2.2)
cordova-plugin-actionsheet (2.3.3)
cordova-plugin-background-fetch (5.6.1)
cordova-plugin-cocoalumberjack (0.0.4)
cordova-plugin-dialogs (2.0.2)
cordova-plugin-sim (1.3.3)
cordova-sqlite-storage (3.4.0)
cordova-support-google-services (1.3.1)
phonegap-plugin-multidex (1.0.0)

@josh-m-sharpe
Copy link
Contributor

josh-m-sharpe commented Oct 24, 2019

I tested this by doing the following:

  1. fork this branch locally
  2. rebase against @capacitor/1.3.0 (released hours ago)
  3. cd cli && npm build
  4. cd core && npm build
  5. in my project: npm link ~/path/to/capacitor/cli
  6. in my project: npm link ~/path/to/capacitor/core
  7. cap add android

I then opened android studio and ran Refactor -> Migrate to AndroidX. That found some additional changes in android/app/build.gradle and android/app/src/main/AndroidManifest.xml

Here's that diff:

diff --git a/android/app/build.gradle b/android/app/build.gradle
index eabb755..d634287 100644
--- a/android/app/build.gradle
+++ b/android/app/build.gradle
@@ -8,7 +8,7 @@ android {
         targetSdkVersion 28
         versionCode 1
         versionName "1.0"
-        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
+        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
     }
     buildTypes {
         release {
@@ -29,11 +29,11 @@ repositories {
 
 dependencies {
     implementation fileTree(include: ['*.jar'], dir: 'libs')
-    implementation 'com.android.support:appcompat-v7:28.0.0'
+    implementation 'androidx.appcompat:appcompat:1.0.0'
     implementation project(':capacitor-android')
     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'
+    androidTestImplementation 'androidx.test.ext:junit:1.1.1'
+    androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.0'
     implementation project(':capacitor-cordova-android-plugins')
 }
 
diff --git a/android/app/src/main/AndroidManifest.xml b/android/app/src/main/AndroidManifest.xml
index d416e80..af50629 100644
--- a/android/app/src/main/AndroidManifest.xml
+++ b/android/app/src/main/AndroidManifest.xml
@@ -32,7 +32,7 @@
         </activity>
 
         <provider
-            android:name="android.support.v4.content.FileProvider"
+            android:name="androidx.core.content.FileProvider"
             android:authorities="${applicationId}.fileprovider"
             android:exported="false"
             android:grantUriPermissions="true">

@PR1YANKPAT3L Should those deps also be updated with this PR?

@josh-m-sharpe
Copy link
Contributor

josh-m-sharpe commented Oct 24, 2019

This seems like something worth merging ASAP. I see it's on the 2.0 milestone, but https://github.com/ionic-team/capacitor/milestones doesn't strike me as being up to date. @jcesarmobile could you add some insight there?

Edit - sorry, I see the milestones have been updated recently. What's going on there? Why are there only 1.1.0 and 2.0.0 milestones when there are 4 released versions since 1.1.0?

@jcesarmobile
Copy link
Member

It’s in the 2.0.0 milestone because it’s a breaking change, so can’t be merged ASAP

@josh-m-sharpe
Copy link
Contributor

@jcesarmobile no comment on the lack of milestone maintenance or insight into what's blocking this? Please advise as to what needs to happen to get this released.

@jcesarmobile
Copy link
Member

The only milestone I’m maintaining is 2.0.0 to track all the required breaking changes.
I didn’t create the other milestones so I can speak about them because I don’t know.

@priyankpat
Copy link
Contributor Author

@josh-m-sharpe Thanks for the feedback. I am looking into it, will post updates/changes in a few hours.

@josh-m-sharpe
Copy link
Contributor

@PR1YANKPAT3L nice update. After running android studio's migration I no longer see a diff.

After clicking Run, I get this error though:

Compilation is not supported for following modules: capacitor-android, capacitor-fcm. Unfortunately you can't have non-Gradle Java modules and Android-Gradle modules in one project.

guessing I added capacitor-android incorrectly? I've added it with yarn add ~/capacitor/android

@josh-m-sharpe
Copy link
Contributor

@jcesarmobile What is the plan for 2.0.0?

@josh-m-sharpe
Copy link
Contributor

josh-m-sharpe commented Oct 26, 2019

@PR1YANKPAT3L following up on the previous comment... I'm definitely having trouble linking to a local version of @capacitor/android. As of this writing, I'm installing it into my project like this:

git clone https://github.com/PR1YANKPAT3L/capacitor.git ~/capacitor
cd ~/capacitor/cli
npm install
npm run-script build
cd ~/capacitor/core
npm install
npm run-script build
cd ~/myProject
yarn add -D ../capacitor/cli
yarn add ../capacitor/core
yarn add ../capacitor/android

Then, when I build android, I get a whole slew of errors like the ones below, all referencing node_modules/@capacitor/android instead of my local version.

  symbol:   class CustomTabsServiceConnection
  location: package android.support.customtabs
/Users/vagrant/git/node_modules/@capacitor/android/capacitor/src/main/java/com/getcapacitor/plugin/Browser.java:12: error: cannot find symbol
import android.support.customtabs.CustomTabsSession;

and

/Users/vagrant/git/node_modules/@capacitor/android/capacitor/src/main/java/com/getcapacitor/plugin/background/BackgroundTask.java:8: error: package android.support.v4.content does not exist
import android.support.v4.content.LocalBroadcastManager;

How are you installing/linking/whatever your local version such that you can use it in a project?

Thanks!

@priyankpat
Copy link
Contributor Author

priyankpat commented Oct 27, 2019

@josh-m-sharpe I recorded the process for easy install: Link

NOTE: It's important to checkout develop branch as it contains the AndroidX support. I am keeping develop up to date from upstream.

Commands I used in sequence (Starting from your project root directory):

cd ..
git clone https://github.com/PR1YANKPAT3L/capacitor.git
cd capacitor
git checkout develop
cd ..
cd ./example-project
npm i ../capacitor/android --save
npx cap sync
npx cap open android

Copy link
Member

@jcesarmobile jcesarmobile left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You missed a few, but I'll fix it in a separate PR.
Other than that, it looks good, thanks!

@jcesarmobile jcesarmobile changed the title Add AndroidX support feat(android): Use AndroidX Feb 18, 2020
@jcesarmobile jcesarmobile changed the title feat(android): Use AndroidX feat(android): Use AndroidX dependencies Feb 18, 2020
@jcesarmobile jcesarmobile changed the title feat(android): Use AndroidX dependencies feat(android): Enable AndroidX and use AndroidX dependencies Feb 18, 2020
@jcesarmobile jcesarmobile merged commit 8b606e9 into ionic-team:master Feb 18, 2020
peterennis added a commit to peterennis/capacitor that referenced this pull request Feb 19, 2020
feat(android): Enable AndroidX and use AndroidX dependencies (ionic-team#2045)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants