Capacitor: “error: package android.support.v4.content does not exist”

Created on 14 Jun 2019  Â·  25Comments  Â·  Source: ionic-team/capacitor

Description of the problem:
When trying to build the SDK with Android Studio on Mac I get:
“error: package android.support.v4.content does not exist”

Affected platform

  • [x] Android

OS of the development machine

  • [x] macOS

Other information:
The build.gradle

// Top-level build file where you can add configuration options common to all sub-projects/modules.

buildscript {

    repositories {
        google()
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.4.1'
        classpath 'com.google.gms:google-services:4.2.0'

        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}

allprojects {
    repositories {
        google()
        jcenter()
    }
}

task clean(type: Delete) {
    delete rootProject.buildDir
}

Capacitor version:
1.0.0

node version:
v12.1.0
npm version:
6.9.0

CocoaPods version:
It's Android that's giving issues

Steps to reproduce:
Probably a bug in my system, so don't know how to reproduce it somewhere else.

Link to sample project:
Don't have it

Most helpful comment

Hi All,

Please install below plugin , it's 100% working.

if Ionic 3/4 any.

ionic cordova plugin add cordova-plugin-androidx-adapter

Normal cordova

cordova plugin add cordova-plugin-androidx-adapter

All 25 comments

Are you using Android Studio 3.4 and gradle 5.1.1?

Might be related to that, I have not tested with those versions and you have updated com.android.tools.build:gradle to a newer version than the one capacitor ships with.

I do use Studio 3.4.1, but I don't know about Gradle. What version specificly do I have to update where? Have zero Android experience.

When you added android platform, the first time you opened it in Android Studio it probably asked you if you wanted to update dependencies and you clicked yes, so it automatically updated com.android.tools.build:gradle and the gradle wrapper.
Try removing android platform and adding it again and this time don't click yes when it ask you if you want to update and check if it works this time.

But anyway, this is something we should fix if it's related to that.

I'm seeing this too. I can confirm that the issue happens once you upgrade the android project.

The issue happens in the capacitor package, since it imports

import android.support.v4.content.LocalBroadcastManager;

in:

/node_modules/@capacitor/android/capacitor/src/main/java/com/getcapacitor/plugin/background/BackgroundTaskService.java
/node_modules/@capacitor/android/capacitor/src/main/java/com/getcapacitor/ui/ModalsBottomSheetDialogFragment.java
/node_modules/@capacitor/android/capacitor/src/main/java/com/getcapacitor/plugin/background/BackgroundTask.java

In my case is Gradle 3.4.1 and Android Studio 3.4

Have the same as @alterx

I updated Android Studio and gradle and still couldn't reproduce.

But today testing a different thing I got a similar error where gradle wasn't finding a package and deleting ~/.gradle/caches fixed the issue. Not sure if will also fix your problem, but you can try.

Same probleme with :
classpath 'com.android.tools.build:gradle:3.3.2'
gradle-4.10.1

I'm seeing this too. I can confirm that the issue happens once you upgrade the android project.

The issue happens in the capacitor package, since it imports

import android.support.v4.content.LocalBroadcastManager;

in:

/node_modules/@capacitor/android/capacitor/src/main/java/com/getcapacitor/plugin/background/BackgroundTaskService.java
/node_modules/@capacitor/android/capacitor/src/main/java/com/getcapacitor/ui/ModalsBottomSheetDialogFragment.java
/node_modules/@capacitor/android/capacitor/src/main/java/com/getcapacitor/plugin/background/BackgroundTask.java

In my case is Gradle 3.4.1 and Android Studio 3.4

I am also facing the exact same issue but with gradle 3.3.2 and capacitor 1.1.1 versions

currently i'm facing a problem following version error:

implementation 'com.android.support:appcompat-v7:28.0.0' in android/app/build.gradle

All com.android.support libraries must use the exact same version specification (mixing versions can lead to runtime crashes). Found versions 28.0.0, 27.1.1. Examples include com.android.support:animated-vector-drawable:28.0.0 and com.android.support:support-media-compat:27.1.1
when i install an Ionic Native plugin.

so when i open the file file capacitor-cordoba-android-plugins i see an error in the following line:
implementation "com.android.support:support-v4:27.+"
when i update it to the version: v7:28.0.0 seems like the problem is solved, but i don't know if that is an error because of me or it's a capacitor issue. please somebody help or give me and advice.

Same here on Linux Android Studio.

Hi All,

Please install below plugin , it's 100% working.

if Ionic 3/4 any.

ionic cordova plugin add cordova-plugin-androidx-adapter

Normal cordova

cordova plugin add cordova-plugin-androidx-adapter

I solved this. Thank you !
cordova plugin add cordova-plugin-androidx-adapter

Looks like it's related to some plugin using Android X.

Capacitor 2.0 will support Android X

https://github.com/ionic-team/capacitor/issues/1937

I have the same problem
When trying to build the SDK with Android Studio on Mac I get:
“error: package android.support.v4.content does not exist”

Affected platform

Android
OS of the development machine

macOS
Other information:
The build.gradle

// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.6.1'
classpath 'com.google.gms:google-services:4.3.3'
}
}
apply from: "variables.gradle"
allprojects {
repositories {
google()
jcenter()
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}

Capacitor version:
2.0.1
node version:
v12.16.1
npm version:
6.13.4
ionic/angular
5.0.0
Android Studio
3.6.3

Workaround:
Following the migration guide fixed it for me manually:
https://capacitor.ionicframework.com/docs/android/updating/
Refactor -> Migrate to AndroidX in AndroidStudio.

I already migrated to android X however I keep presenting the same problem the app does not compile in android, in ios it works.

Also, have this issue with Android X

SOLUTION TO
error: package android.support.v4.content does not exist
import android.support.v4.content.FileProvider;

using jetify helped to solve .

from @ jcesarmobile' s post --- >https://github.com/ionic-team/capacitor/pull/2832

Error: "package android.support.* does not exist"
This error occurs when some Cordova or Capacitor plugin has old android support dependencies instead of using the new AndroidX equivalent.
You should report the issue in the plugin repository so the maintainers can update the plugin to use AndroidX dependencies.

As workaround you can also patch the plugin using jetifier

npm install jetifier
npx jetify
npx cap sync android

I upgrade to AndroidX. In local, it works, but when you run npx cap sync android this dependency is replaced in android/app/capacitor.build.gradle:

dependencies {
    implementation project(':capacitor-analytics')
    implementation project(':capacitor-firebase-auth')
-   implementation 'androidx.legacy:legacy-support-v4:1.0.0'
+   implementation "com.android.support:support-v4:27.+"
}

In local I can rollback this automatic change, but in AppFlow I'm not able to build.

I'm using capacitor v2

SOLUTION TO
error: package android.support.v4.content does not exist
import android.support.v4.content.FileProvider;

using jetify helped to solve .

from @ jcesarmobile' s post --- >#2832

Error: "package android.support.* does not exist"
This error occurs when some Cordova or Capacitor plugin has old android support dependencies instead of using the new AndroidX equivalent.
You should report the issue in the plugin repository so the maintainers can update the plugin to use AndroidX dependencies.

As workaround you can also patch the plugin using jetifier

npm install jetifier
npx jetify
npx cap sync android

thx dude

I solved this. Thank you!
cordova plugin add cordova-plugin-androidx-adapter

SOLUTION TO
error: package android.support.v4.content does not exist
import android.support.v4.content.FileProvider;

using jetify helped to solve .

from @ jcesarmobile' s post --- >#2832

Error: "package android.support.* does not exist"
This error occurs when some Cordova or Capacitor plugin has old android support dependencies instead of using the new AndroidX equivalent.
You should report the issue in the plugin repository so the maintainers can update the plugin to use AndroidX dependencies.

As workaround you can also patch the plugin using jetifier

npm install jetifier
npx jetify
npx cap sync android

It works!! I just install cordova Camera with capacitor

Hi All,

Please install below plugin , it's 100% working.

if Ionic 3/4 any.

ionic cordova plugin add cordova-plugin-androidx-adapter

Normal cordova

cordova plugin add cordova-plugin-androidx-adapter

**Working on Ionic 5.
Thanks

Hi All,

Please install below plugin , it's 100% working.

if Ionic 3/4 any.

ionic cordova plugin add cordova-plugin-androidx-adapter

Normal cordova

cordova plugin add cordova-plugin-androidx-adapter

Yes, this resolved my issue. Thanks you save my day

Was this page helpful?
0 / 5 - 0 ratings

Related issues

natevw picture natevw  Â·  3Comments

mlynch picture mlynch  Â·  3Comments

alexcroox picture alexcroox  Â·  3Comments

stripathix picture stripathix  Â·  3Comments

gnesher picture gnesher  Â·  3Comments