spoonconsulting / cordova-plugin-background-upload

Cordova plugin for background upload
Apache License 2.0
49 stars 53 forks source link

Using plugin with capacitor throws error on androidx.lifecycle #174

Closed hanslbua closed 2 years ago

hanslbua commented 2 years ago

Hi, when i install the plugin with capacitor with the command line npm install @spoonconsulting/cordova-plugin-background-upload@latest i get an error after building the app.

Error Msg:

> Task :capacitor-cordova-android-plugins:compileDebugJavaWithJavacwarning: unknown enum constant androidx.lifecycle.Lifecycle$Event.ON_RESUME
 reason: class file for androidx.lifecycle.Lifecycle$Event not found
 warning: unknown enum constant androidx.lifecycle.Lifecycle$Event.ON_PAUSE

android\capacitor-cordova-android-plugins\src\main\java\com\spoon\backgroundfileupload\FileTransferBackground.java:163: error: cannot access androidx.lifecycle.LifecycleObserver
this.globalObserver.register();
^
class file for androidx.lifecycle.LifecycleObserver not found

Package.json "@spoonconsulting/cordova-plugin-background-upload": "^2.0.7", "cordova-plugin-androidx": "^3.0.0", "cordova-plugin-androidx-adapter": "^1.1.3"

Can someone help me with the problem?

zfir commented 2 years ago

Hello @hanslbua,

I have created an Test app with Ionic Capcitor and it is building the app successfully. Here is the package.json:

{
  "name": "testApp",
  "version": "0.0.1",
  "author": "Ionic Framework",
  "homepage": "https://ionicframework.com/",
  "scripts": {
    "ng": "ng",
    "start": "ng serve",
    "build": "ng build",
    "test": "ng test",
    "lint": "ng lint",
    "e2e": "ng e2e"
  },
  "private": true,
  "dependencies": {
    "@angular/common": "~13.0.0",
    "@angular/core": "~13.0.0",
    "@angular/forms": "~13.0.0",
    "@angular/platform-browser": "~13.0.0",
    "@angular/platform-browser-dynamic": "~13.0.0",
    "@angular/router": "~13.0.0",
    "@capacitor/android": "^3.4.0",
    "@capacitor/app": "1.1.0",
    "@capacitor/core": "3.4.0",
    "@capacitor/haptics": "1.1.4",
    "@capacitor/keyboard": "1.2.1",
    "@capacitor/status-bar": "1.0.7",
    "@ionic/angular": "^6.0.0",
    "@spoonconsulting/cordova-plugin-background-upload": "^2.0.7",
    "rxjs": "~6.6.0",
    "tslib": "^2.2.0",
    "zone.js": "~0.11.4"
  },
  "devDependencies": {
    "@angular-devkit/build-angular": "~13.0.1",
    "@angular-eslint/builder": "~13.0.1",
    "@angular-eslint/eslint-plugin": "~13.0.1",
    "@angular-eslint/eslint-plugin-template": "~13.0.1",
    "@angular-eslint/template-parser": "~13.0.1",
    "@angular/cli": "~13.0.1",
    "@angular/compiler": "~13.0.0",
    "@angular/compiler-cli": "~13.0.0",
    "@angular/language-service": "~13.0.0",
    "@capacitor/cli": "3.4.0",
    "@ionic/angular-toolkit": "^5.0.0",
    "@types/jasmine": "~3.6.0",
    "@types/jasminewd2": "~2.0.3",
    "@types/node": "^12.11.1",
    "@typescript-eslint/eslint-plugin": "5.3.0",
    "@typescript-eslint/parser": "5.3.0",
    "eslint": "^7.6.0",
    "eslint-plugin-import": "2.22.1",
    "eslint-plugin-jsdoc": "30.7.6",
    "eslint-plugin-prefer-arrow": "1.2.2",
    "jasmine-core": "~3.8.0",
    "jasmine-spec-reporter": "~5.0.0",
    "karma": "~6.3.2",
    "karma-chrome-launcher": "~3.1.0",
    "karma-coverage": "~2.0.3",
    "karma-coverage-istanbul-reporter": "~3.0.2",
    "karma-jasmine": "~4.0.0",
    "karma-jasmine-html-reporter": "^1.5.0",
    "protractor": "~7.0.0",
    "ts-node": "~8.3.0",
    "typescript": "~4.4.4"
  },
  "description": "An Ionic project"
}

Regards, Zafir. Spoon Consulting LTD

hanslbua commented 2 years ago

Hey. thanks for your answer.

i saw, that you dont installed the androidx and androidx-adapter plugin. i removed it now from my project.

which command do you use? npm run build? with that command it runs successfully.

but when i use: iconic capacitor run android it crashes

it also says: that i have to intall the dependencies androidx and androidx-adapter

cheers, Hans-Peter

zfir commented 2 years ago

Hello @hanslbua,

I have run ionic build first and run npx cap add android. Then, I open the android folder on Android Studio. Try this and let me know.

Regards, Zafir. Spoon Consulting LTD

hanslbua commented 2 years ago

Hey @zafirskthelifehacker,

thanks for your answer.

I tried it your way but get also the same error, but in Android Studio after running the app.

image image image

Cheers Hans-Peter

zfir commented 2 years ago

Hello @hanslbua,

Can you specify the SDK Build Tools that you are using and also the targetSDKVersion for your app.

Regards, Zafir. Spoon Consulting LTD

hanslbua commented 2 years ago

Hi @zafirskthelifehacker,

settings.gradle

ext {
    min9SdkVersion = 21
    compileSdkVersion = 30
    targetSdkVersion = 30
    androidxActivityVersion = '1.2.0'
    androidxAppCompatVersion = '1.2.0'
    androidxCoordinatorLayoutVersion = '1.1.0'
    androidxCoreVersion = '1.3.2'
    androidxFragmentVersion = '1.3.0'
    junitVersion = '4.13.1'
    androidxJunitVersion = '1.1.2'
    androidxEspressoCoreVersion = '3.3.0'
    cordovaAndroidVersion = '7.0.0'
}

Android SDK Build-Tools 32 (build-tools;32.0.0)

Cheers, Hans-Peter

zfir commented 2 years ago

Hello @hanslbua,

Can you try Android SDK Build Tools version 30.0.3.

Regards, Zafir. Spoon Consulting LTD

hanslbua commented 2 years ago

Hi @zafirskthelifehacker,

i tried with 30.0.2, 30.0.3 and 32.0.0 without success :(

Cheers, Hans-Peter

zfir commented 2 years ago

Hello @hanslbua,

Can you try to add this in your gradle.properties files(in android folder) and build again?

android.useAndroidX=true
android.enableJetifier=true

Regards, Zafir. Spoon Consulting LTD

hanslbua commented 2 years ago

Hi @zafirskthelifehacker,

i have this setting allready in my gradle.properties file.

:(

cheers, Hans-Peter

zfir commented 2 years ago

Hello @hanslbua,

As per this stackoverflow (https://stackoverflow.com/questions/49485847/error-cannot-access-lifecycleobserver), adding this Google repository can help(Add in build.gradle in the android folder):

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

If not, try to see other answers regarding this issue on the stackoverflow or try to create another project from scratch with only the plugin.

Regards, Zafir. Spoon Consulting LTD

hanslbua commented 2 years ago

Hey @zafirskthelifehacker,

this is my 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:4.2.1'
        classpath 'com.google.gms:google-services:4.3.5'

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

apply from: "variables.gradle"

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

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

:( its so frustrating that its not working. i will try a new project tomorrow and let you know.

Cheers.

hanslbua commented 2 years ago

we can close it here. i fixed it by create a new project from scratch. now it works.