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

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

Closed
2 tasks done
renege opened this issue Jun 14, 2019 · 28 comments
Closed
2 tasks done

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

renege opened this issue Jun 14, 2019 · 28 comments

Comments

@renege
Copy link

renege commented Jun 14, 2019

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

  • 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.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

@jcesarmobile
Copy link
Member

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.

@renege
Copy link
Author

renege commented Jun 19, 2019

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.

@jcesarmobile
Copy link
Member

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.

@alterx
Copy link

alterx commented Jun 19, 2019

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

@renege
Copy link
Author

renege commented Jun 20, 2019

Have the same as @alterx

@jcesarmobile
Copy link
Member

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.

@BeliliFahem
Copy link

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

@nagarjuna993
Copy link

nagarjuna993 commented Jul 30, 2019

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

@edu1998
Copy link

edu1998 commented Oct 9, 2019

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.

@OoDeLally
Copy link

Same here on Linux Android Studio.

@yogeshpatil143
Copy link

yogeshpatil143 commented Dec 24, 2019

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

@naive924
Copy link

naive924 commented Jan 9, 2020

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

@jcesarmobile
Copy link
Member

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

Capacitor 2.0 will support Android X

#1937

@ionic-team ionic-team deleted a comment from dhrn Apr 10, 2020
@Hansel03
Copy link

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

@cleanerx
Copy link

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

@Hansel03
Copy link

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

@StefanVanStaden
Copy link

Also, have this issue with Android X

@deborahjames
Copy link

deborahjames commented Jun 2, 2020

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

@nelson6e65
Copy link

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.

@nelson6e65
Copy link

I'm using capacitor v2

@gknbrdl
Copy link

gknbrdl commented Jul 27, 2020

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

@LakshanKariyawasam
Copy link

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

@willyleon
Copy link

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

@mrbhaskar
Copy link

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

@hemantdhivar
Copy link

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

@anthonyplews
Copy link

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

Thank you!

@rohitmali26
Copy link

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

Thank You

@mamta-99
Copy link

mamta-99 commented Jul 7, 2021

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

thank you so much...... it worked for me

@ionic-team ionic-team locked as resolved and limited conversation to collaborators Jul 7, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests