-
Notifications
You must be signed in to change notification settings - Fork 1k
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
npx cap sync android returns [error] Package could not be parsed from Android plugin. #4855
Comments
If you don't include the plug-in in your Android build, re-run |
Hi @thomasvidas, thanks for your answer I think it didn't work, these are the steps: Uninstall plug-in:
Sync:
(I get the warning for iOS because I haven't adapted the iOS plugins to capacitor 3) Install plug-in:
Sync:
I have to say that the file which the error shows changes randomly
You mean the gradle file in the plug-in or the gradle file in the project? |
@thomasvidas any idea what's the problem? Do you need any other info? |
I've discovered that if I delete the file it's giving problems
But if I keep doing
|
Hmm...This sounds like an issue specific to your project and not an issue with capacitor. If you can provide a minimal reproduction the team can take a better look at it to see if it is an issue on our side |
This issue may need more information before it can be addressed. In particular, it will need a reliable Code Reproduction that demonstrates the issue. Please see the Contributing Guide for how to create a Code Reproduction. Thanks! |
Thanks for your answer @thomasvidas I've created a repo with an example of the problem: https://github.com/CarlosNano/error-importing-capacitor It's a new project of the plugin in capacitor with a copy of the files we use in our project. I've emptied the classes so I can make the repo public. It happens the same problem as described before, but be aware that the error sometimes it's a bit random. Let me know if you need anything else. |
Capacitor CLI only expects to have a Plugin class per plugin, but your sample plugin has three plugin classes. The error is misleading, not sure why that happens, and only happens when you have at least a java plugin and a kotlin plugin. If having multiple java plugins or multiple kotlin plugins alone but not mixed, the error doesn't show up, but still, only one of the plugins will be registered as the CLI only expects to have one plugin per package. |
Thanks a lot for taking a lot to this, I assume when you talk about plugin classes you are referring to classes with the annotation What's the implication of having multiple classes but only one is registered in the CLI? The other classes won't be accessible from the Javascript Code? or the other classes will be ignored if there is any errors on them? Is there any plans to adopt having multiple plugin classes per plugin? Also I assume this is a problem introduced in Capacitor 3 because, I didn't have any errors in Capacitor 2 ( which I guess it would not mean the CLI registered multiple classes either ) |
Capacitor 3 introduced the automatic plugin registration, but it expect to only have a plugin class per package, so in cases like yours where there are more than one, they won't automatically register, so plugin users will still have to add code in their MainActivity.java to register plugins. But since it will randomly register one of them will be hard for users to register the missing ones, not sure what happens if you register one that is already registered by Capacitor. You can keep the init method in the MainActivity.java so you opt out of the automatic registration, but the CLI will still fail. About the plans, no idea, we were not aware of anybody doing this and I don't think it's a common thing to do, so we will have to see if it's a common feature to add as it's not a trivial change to do. |
Something worth to try :)
The CLI will still fail as long as I use Java and Kotlin, if I use only Kotlin, it should be ok, isn't it? |
the error will be gone, but it will just register one of them, so not 100% ok |
Ok, I will try registering all of them, because as you said, the CLI will randomly register one of them and I assume there is no way to ask which one has been registered already. Hopefully registering twice to that one plugin class will be ok 🤞 Thanks |
I've just updated the only class in Java to Kotlin, but I'm still getting the same error in the CLI when I do (I also tried to remove the plugin, sync, add the plugin and sync ) Is there anything else I need to do so I don't get the error.
|
then maybe it was because of having different packages and not because of being java/kotlin, if I delete the java class the error goes away, but didn't try adding a kotlin class in that existing package |
Mmm, the error is very random, I'm almost sure if you keep running So I guess for your answer, it's not possible to have multiple plugin classes in a plugin? |
I tried multiple times (a lot) and didn't get an error once the java class was gone |
You are right if I remove the class But if I add it back converted as Kotlin, the error is back too :_( . Also I put all files in the same package, same error. I've updated the code if you want to take a look. |
Looks like the problem is then having different packages per plugin, but I don't have more time to dedicate to this, for now our official stand is that we only support a plugin class per plugin package and that causes the issue. Will leave the issue open in case we add support for multiple plugin classes in the future. |
That's great. Thanks for your help |
I found this bug: |
Thanks for the issue! This issue is being locked to prevent comments that are not relevant to the original issue. If this is still an issue with the latest version of Capacitor, please create a new issue and ensure the template is fully filled out. |
Bug Report
Capacitor Version
Platform(s)
Android
Current Behavior
When I run
npx cap sync android
I get the following error:✔ Copying web assets from www to android/app/src/main/assets/public in 2.80s
✔ Creating capacitor.config.json in android/app/src/main/assets in 1.76ms
✔ copy android in 2.83s
✔ Updating Android plugins in 13.18ms
[info] Found 1 Capacitor plugin for android:
[email protected]
✖ update android - failed!
[error] Package could not be parsed from Android plugin.
Location:
/Users/myUser/myPath/Sso.kt
Could you please point me to what it could be wrong?
When I compile the plugin on its own in Android studio I get no compilation errors.
Thanks
Expected Behavior
Run
npx cap sync android
with no errorsOther Technical Details
npm --version output: 7.8.0
node --version output: v14.11.0
The text was updated successfully, but these errors were encountered: