transistorsoft / flutter_background_fetch

Periodic callbacks in the background for both IOS and Android. Includes Android Headless mechanism
MIT License
568 stars 165 forks source link

[BUG]`/example` doesn't work in a specific environment #372

Closed Mitsutan closed 3 months ago

Mitsutan commented 3 months ago

Your Environment

[√] Windows Version (Installed version of Windows is version 10 or higher)

[√] Android toolchain - develop for Android devices (Android SDK version 34.0.0) • Android SDK at C:\Users\foo\AppData\Local\Android\sdk • Platform android-34, build-tools 34.0.0 • Java binary at: C:\Program Files\Android\Android Studio\jbr\bin\java • Java version OpenJDK Runtime Environment (build 17.0.7+0-b2043.56-10550314) • All Android licenses accepted.

[√] Chrome - develop for the web • Chrome at C:\Program Files\Google\Chrome\Application\chrome.exe

[X] Visual Studio - develop Windows apps X Visual Studio not installed; this is necessary to develop Windows apps. Download at https://visualstudio.microsoft.com/downloads/. Please install the "Desktop development with C++" workload, including all of its default components

[√] Android Studio (version 2023.1) • Android Studio at C:\Program Files\Android\Android Studio • Flutter plugin can be installed from: https://plugins.jetbrains.com/plugin/9212-flutter • Dart plugin can be installed from: https://plugins.jetbrains.com/plugin/6351-dart • Java version OpenJDK Runtime Environment (build 17.0.7+0-b2043.56-10550314)

[√] VS Code (version 1.89.1) • VS Code at C:\Users\foo\AppData\Local\Programs\Microsoft VS Code • Flutter extension version 3.90.0

[√] Connected device (4 available) • S4 KC (mobile) • 195309360212 • android-arm64 • Android 10 (API 29) • Windows (desktop) • windows • windows-x64 • Microsoft Windows [Version 10.0.19045.4412] • Chrome (web) • chrome • web-javascript • Google Chrome 125.0.6422.113 • Edge (web) • edge • web-javascript • Microsoft Edge 123.0.2420.97

[√] Network resources • All expected network resources are available.

! Doctor found issues in 1 category.

* Plugin config

**To Reproduce**
Steps to reproduce the behavior:
1. Download flutter background fetch from GitHub
2. Open `/example` in VScode
3. run `flutter pub get`
4. run `flutter run -v`

**Debug logs**
Too many log, so this is part of "red line" log.
- Android: 

[ ] C:\Users\foo\Downloads\flutter_background_fetch-master\flutter_background_fetch-master\example\android\app\src\main\java\io\flutter\app\FlutterMultiDexApplication.java:13: �G���[: �p�b�P�[�Wandroidx.multidex�͑��݂��܂��� [ +1 ms] import androidx.multidex.MultiDex; [ ] ^ [ ] C:\Users\foo\Downloads\flutter_background_fetch-master\flutter_background_fetch-master\example\android\app\src\main\java\io\flutter\app\FlutterMultiDexApplication.java:23: �G���[: �V���{�����������܂��� [ ] MultiDex.install(this); [ ] ^ [ ] �V���{��: �ϐ� MultiDex [ ] �ꏊ: �N���X FlutterMultiDexApplication [ ] �G���[2�� [ +566 ms] AAPT2 aapt2-7.3.0-8691043-windows Daemon #0: shutdown [ +186 ms] FAILURE: Build failed with an exception. [ ] * What went wrong: [ ] Execution failed for task ':app:compileDebugJavaWithJavac'.

.
.
.

[ ] at java.base/java.lang.Thread.run(Thread.java:833) [ ] * Get more help at https://help.gradle.org [ ] BUILD FAILED in 1m 3s [ ] 87 actionable tasks: 85 executed, 2 up-to-date [ ] Watched directory hierarchies: [C:\Users\foo\flutter\packages\flutter_tools\gradle, C:\Users\foo\Downloads\flutter_background_fetch-master\flutter_background_fetch-master\example\android] [+1032 ms] Running Gradle task 'assembleDebug'... (completed in 65.3s) [ +22 ms] Error: Gradle task assembleDebug failed with exit code 1



**Additional context**
I use translator, maybe some wrong English.

I tried to run an example to check how this library works.
However, several warnings were output in vscode, and of course it wouldn't start.
![スクリーンショット (595)](https://github.com/transistorsoft/flutter_background_fetch/assets/83488293/dbcade0f-f859-4c68-b243-67c1c0234039)

I can start new projects and examples of other libraries.

Strangely enough, if I do the same thing on another PC, it starts up.
Therefore, there is a possibility that my PC environment and the example of this library are incompatible.
What is affecting this?
Please let me know if you need any more information about my PC environment.

***what I tried***
- run `dart fix --apply`
- cache clear flutter and gradle
- upgrade flutter
- edit `minSdkVersion` to 29
Mitsutan commented 3 months ago

Is anyone there? I still progressing this problem. I don't know if this is related to the issue, but here is my java version information:

$ java --version
openjdk 18.0.1 2022-04-19
OpenJDK Runtime Environment (build 18.0.1+10-24)
OpenJDK 64-Bit Server VM (build 18.0.1+10-24, mixed mode, sharing)
Mitsutan commented 3 months ago

Hey, I have good news! I was able to run it successfully by adding the following line to android/app/build.gradle:

This is final code:

plugins {
    id "com.android.application"
    id "kotlin-android"
    id "dev.flutter.flutter-gradle-plugin"
}

def localProperties = new Properties()
def localPropertiesFile = rootProject.file('local.properties')
if (localPropertiesFile.exists()) {
    localPropertiesFile.withReader('UTF-8') { reader ->
        localProperties.load(reader)
    }
}

def flutterVersionCode = localProperties.getProperty('flutter.versionCode')
if (flutterVersionCode == null) {
    flutterVersionCode = '1'
}

def flutterVersionName = localProperties.getProperty('flutter.versionName')
if (flutterVersionName == null) {
    flutterVersionName = '1.0'
}

android {
    namespace 'com.transistorsoft.flutter.backgroundfetch.backgroundfetchexample'

    compileSdkVersion rootProject.ext.compileSdkVersion
    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }

    kotlinOptions {
        jvmTarget = '1.8'
    }

    sourceSets {
        main.java.srcDirs += 'src/main/kotlin'
    }

    defaultConfig {
        // TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
        applicationId "com.transistorsoft.flutter.backgroundfetch.backgroundfetchexample"
        minSdkVersion flutter.minSdkVersion
        targetSdkVersion rootProject.ext.targetSdkVersion
        versionCode flutterVersionCode.toInteger()
        versionName flutterVersionName
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
        multiDexEnabled true
    }

    buildTypes {
        release {
            // TODO: Add your own signing config for the release build.
            // Signing with the debug keys for now, so `flutter run --release` works.
            minifyEnabled true
            shrinkResources false
            signingConfig signingConfigs.debug
        }
    }
}

flutter {
    source '../..'
}

dependencies {
    implementation "androidx.multidex:multidex:2.0.0"
}

I don't know why I need to explicitly enable multiDexEnabled true when running on this PC even though the sdkVersion is specified as 34, but anyway, it worked this time, so I'm happy with it. Does anyone know more about this?

WingCH commented 2 months ago

same issue, cannot build in android

Doctor summary (to see all details, run flutter doctor -v):
[✓] Flutter (Channel stable, 3.22.2, on macOS 14.5 23F79 darwin-arm64, locale zh-Hant-HK)
[✓] Android toolchain - develop for Android devices (Android SDK version 34.0.0)
[✓] Xcode - develop for iOS and macOS (Xcode 15.4)
[✓] Chrome - develop for the web
[✓] Android Studio (version 2024.1)
[✓] IntelliJ IDEA Community Edition (version 2023.3.2)
[✓] VS Code (version 1.90.2)
[✓] Connected device (7 available)
[✓] Network resources
christocracy commented 2 months ago

did you try the above?

WingCH commented 2 months ago

Yes, this solution works, but I suggest adding an example or a readme to inform new users about this common issue.

christocracy commented 2 months ago

The /example is simply going to implement multidex with two simple lines of code.

christocracy commented 2 months ago

multidex implemented in /example and merged to master.