AngeloAvv / flutter_flavorizr

A flutter utility to easily create flavors in your flutter application
https://pub.dev/packages/flutter_flavorizr
MIT License
456 stars 81 forks source link

flutter pub run flutter_flavorizr error #188

Closed RoyZengTW closed 1 year ago

RoyZengTW commented 1 year ago

After I add the flavorizr in pubspec.yaml, I run flutter pub run flutter_flavorizr in terminal. I got error

Executing task android:buildGradle Unhandled exception: The following resource contains existing flavor dimensions:

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

def flutterRoot = localProperties.getProperty('flutter.sdk')
if (flutterRoot == null) {
    throw GradleException("Flutter SDK not found. Define location with flutter.sdk in the local.properties file.")
}

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

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

apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle"

android {
    compileSdkVersion 33
    ndkVersion flutter.ndkVersion

    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.xrspace.xrexpo.mobile.xspoclient"
        // You can update the following values to match your application needs.
        // For more information, see: https://docs.flutter.dev/deployment/android#reviewing-the-build-configuration.
        minSdkVersion 24
        targetSdkVersion flutter.targetSdkVersion
        versionCode flutterVersionCode.toInteger()
        versionName flutterVersionName
        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.
            signingConfig signingConfigs.debug
        }
    }

    flavorDimensions "app"
    productFlavors {
        dev {
            applicationIdSuffix ".dev"
        }
        prod {
        }
    }
}

flutter {
    source '../..'
}

dependencies {
    implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
}

. Please delete the whole section before running flutter_flavorizr again.

.0 AndroidBuildGradleProcessor.execute (package:flutter_flavorizr/processors/android/android_build_gradle_processor.dart:67:7)

.1 AbstractFileStringProcessor.execute (package:flutter_flavorizr/processors/commons/abstract_file_string_processor.dart:41:31)

.2 Processor.execute (package:flutter_flavorizr/processors/processor.dart:116:24)

pub finished with exit code 255

Is someone has the same error? How do I fix this? Thanks.

zeref278 commented 1 year ago

Delete the section below, reopen terminal and run flutter pub run flutter_flavorizr again.


    flavorDimensions "app"
    productFlavors {
        dev {
            applicationIdSuffix ".dev"
        }
        prod {
        }
    }
RoyZengTW commented 1 year ago

Thanks for replying. After I delete the section. I got another error

Executing task flutter:targets
Running FlutterTargetFileProcessor
Running Copying file from .tmp/flutter/main_target.dart to lib/main_dev.dart
Running FileProcessor: creating file lib/main_dev.dart with nested ReplaceStringProcessor: replacing [[FLAVOR_NAME]] with dev
Running FlutterTargetFileProcessor
Running Copying file from .tmp/flutter/main_target.dart to lib/main_prod.dart
Running FileProcessor: creating file lib/main_prod.dart with nested ReplaceStringProcessor: replacing [[FLAVOR_NAME]] with prod

Executing task ios:xcconfig
Running IOSXCConfigFileProcessor
Running IOSXCConfigModeFileProcessor
Running FileProcessor: writing file ios/Flutter/devDebug.xcconfig with nested IOSXCConfigProcessor
Running ShellProcessor: Running script 'ruby' with arguments .tmp/scripts/darwin/add_file.rb, ios/Runner.xcodeproj, Flutter/devDebug.xcconfig, Flutter
Unhandled exception:
ProcessException: 系統找不到指定的檔案。

  Command: ruby .tmp/scripts/darwin/add_file.rb ios/Runner.xcodeproj Flutter/devDebug.xcconfig Flutter
#0      _ProcessImpl._runAndWait (dart:io-patch/process_patch.dart:487:7)
#1      _runNonInteractiveProcessSync (dart:io-patch/process_patch.dart:632:18)
#2      Process.runSync (dart:io-patch/process_patch.dart:68:12)
#3      ShellProcessor.execute (package:flutter_flavorizr/src/processors/commons/shell_processor.dart:45:36)
#4      QueueProcessor.execute (package:flutter_flavorizr/src/processors/commons/queue_processor.dart:44:17)
#5      QueueProcessor.execute (package:flutter_flavorizr/src/processors/commons/queue_processor.dart:44:17)
#6      QueueProcessor.execute (package:flutter_flavorizr/src/processors/commons/queue_processor.dart:44:17)
#7      Processor.execute (package:flutter_flavorizr/src/processors/processor.dart:139:24)

The android part seems success and ios is fail. How do I fix the error? Thanks.

RoyZengTW commented 1 year ago

After I install Ruby,Gem and Xcodeproj. It works fine. Thank you.