Error in Android Studio with Capacitor 3
losciur opened this issue · 7 comments
Please post the full code of MainActivity,java
That is the full code...
In the previous image I just cut the first line where there is my package name...
The app is created with ionic angular capacitor 3.
Everything works fine except firebase.
I repost here MainActivity.java:
package it.piemonte.arpa.meteo3RTest;
import com.getcapacitor.BridgeActivity;
import com.getcapacitor.community.firebaseanalytics.FirebaseAnalytics;
public class MainActivity extends BridgeActivity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// Initializes the Bridge
this.init(
savedInstanceState,
new ArrayList<Class<? extends Plugin>>() {
{
// Additional plugins you've installed go here
// Ex: add(TotallyAwesomePlugin.class);
add(FirebaseAnalytics.class);
}
}
);
}
}
Here my npx cap sync android
✔ Copying web assets from www to android/app/src/main/assets/public in 1.77s
✔ Creating capacitor.config.json in android/app/src/main/assets in 1.60ms
⠴ copy android [info] Found 4 Cordova plugins for android:
cordova-plugin-nativegeocoder@3.4.1
cordova-plugin-x-socialsharing@6.0.3
cordova.plugins.diagnostic@6.0.3
es6-promise-plugin@4.2.2
✔ copy android in 1.86s
✔ Updating Android plugins in 31.61ms
[info] Found 11 Capacitor plugins for android:
@capacitor-community/firebase-analytics@1.0.0
@capacitor/app@1.0.0
@capacitor/device@1.0.0
@capacitor/filesystem@1.0.0
@capacitor/geolocation@1.0.0
@capacitor/haptics@1.0.0
@capacitor/keyboard@1.0.0
@capacitor/network@1.0.0
@capacitor/splash-screen@1.0.0
@capacitor/status-bar@1.0.0
@capacitor/storage@1.0.0
⠙ update android [info] Found 4 Cordova plugins for android:
cordova-plugin-nativegeocoder@3.4.1
cordova-plugin-x-socialsharing@6.0.3
cordova.plugins.diagnostic@6.0.3
es6-promise-plugin@4.2.2
✔ update android in 117.29ms
[info] Sync finished in 1.978s
Here my ionic info
Ionic:
Ionic CLI : 6.16.1 (/home/losciur/.nvm/versions/node/v14.17.0/lib/node_modules/@ionic/cli)
Ionic Framework : @ionic/angular 5.6.8
@angular-devkit/build-angular : 12.0.3
@angular-devkit/schematics : 12.0.3
@angular/cli : 12.0.3
@ionic/angular-toolkit : 4.0.0
Capacitor:
Capacitor CLI : 3.0.0
@capacitor/android : 3.0.0
@capacitor/core : 3.0.0
@capacitor/ios : not installed
Utility:
cordova-res : 0.15.3
native-run : 1.3.0
System:
NodeJS : v14.17.0 (/home/losciur/.nvm/versions/node/v14.17.0/bin/node)
npm : 6.14.13
OS : Linux 5.4
import android.os.Bundle;
import com.getcapacitor.BridgeActivity;
import com.getcapacitor.Plugin;
import com.getcapacitor.community.firebaseanalytics.FirebaseAnalytics;
import java.util.ArrayList;
Add these imports in MainActivity.java
This is a duplicate of #94, closing.
Thanks for the help!
Mixing what you suggest and what in capacitor documentation and in #94 I think that the better solution is:
import android.os.Bundle;
import com.getcapacitor.BridgeActivity;
import com.getcapacitor.community.firebaseanalytics.FirebaseAnalytics;
public class MainActivity extends BridgeActivity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
registerPlugin(FirebaseAnalytics.class);
}
}
Maybe you may add this lines in the documentation of this plugin, because the lines you suggest are deprecated.
The capacitor documentation indicates that the registerPlugin
call is not needed for plugins installed via NPM, which is the case for the firebase-analytics plugin. You only need to call registerPlugin
if you have local custom plugins that you developed for your app and are not installing from NPM.
You're right about the capacitor documentation,
but if I leave the code you suggest:
import android.os.Bundle;
import com.getcapacitor.BridgeActivity;
import com.getcapacitor.Plugin;
import com.getcapacitor.community.firebaseanalytics.FirebaseAnalytics;
import java.util.ArrayList;
public class MainActivity extends BridgeActivity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// Initializes the Bridge
this.init(
savedInstanceState,
new ArrayList<Class<? extends Plugin>>() {
{
// Additional plugins you've installed go here
// Ex: add(TotallyAwesomePlugin.class);
add(FirebaseAnalytics.class);
}
}
);
}
}
I got this (Android Studio 4.2.1):
On the other side, when I install any official capacitor plugins via npm I don't have to modify the ManiActivity.java file in Android Studio (I don't know why).
Thank you very much for your work and this explanation words, I'm very happy to try to understand something more in plugin.