Skip to content
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

Circular dependency error in the Android Gradle Plugin #2219

Open
feinstein opened this issue Aug 8, 2024 · 5 comments
Open

Circular dependency error in the Android Gradle Plugin #2219

feinstein opened this issue Aug 8, 2024 · 5 comments

Comments

@feinstein
Copy link

feinstein commented Aug 8, 2024

Platform

Dart

Obfuscation

Enabled

Debug Info

Enabled

Doctor

[✓] Flutter (Channel stable, 3.22.3, on macOS 14.5 23F79 darwin-arm64, locale en-AU)
• Flutter version 3.22.3 on channel stable at /Users/user/.puro/envs/stable/flutter
• Upstream repository https://github.com/flutter/flutter.git
• Framework revision b0850beeb2 (3 weeks ago), 2024-07-16 21:43:41 -0700
• Engine revision 235db911ba
• Dart version 3.4.4
• DevTools version 2.34.3

[✓] Android toolchain - develop for Android devices (Android SDK version 34.0.0)
• Android SDK at /Users/user/Library/Android/sdk
• Platform android-34, build-tools 34.0.0
• ANDROID_HOME = /Users/user/Library/Android/sdk
• Java binary at: /Applications/Android Studio.app/Contents/jbr/Contents/Home/bin/java
• Java version OpenJDK Runtime Environment (build 17.0.11+0-17.0.11b1207.24-11852314)
• All Android licenses accepted.

[✓] Xcode - develop for iOS and macOS (Xcode 15.4)
• Xcode at /Applications/Xcode.app/Contents/Developer
• Build 15F31d
• CocoaPods version 1.15.2

[✓] Chrome - develop for the web
• Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome

[✓] Android Studio (version 2024.1)
• Android Studio at /Applications/Android Studio.app/Contents
• 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.11+0-17.0.11b1207.24-11852314)

[✓] IntelliJ IDEA Community Edition (version 2024.1.1)
• IntelliJ at /Applications/IntelliJ IDEA CE.app
• Flutter plugin version 79.0.3
• Dart plugin version 241.15989.9

[✓] VS Code (version 1.91.1)
• VS Code at /Applications/Visual Studio Code.app/Contents
• Flutter extension version 3.88.0

[✓] Connected device (5 available)
• sdk gphone64 arm64 (mobile) • emulator-5554 • android-arm64 • Android 14 (API 34) (emulator)
• iPhone 15 Pro (mobile) • D18F35A4-68A7-4B23-8353-9D087BE9AEDB • ios • com.apple.CoreSimulator.SimRuntime.iOS-17-5 (simulator)
• macOS (desktop) • macos • darwin-arm64 • macOS 14.5 23F79 darwin-arm64
• Mac Designed for iPad (desktop) • mac-designed-for-ipad • darwin • macOS 14.5 23F79 darwin-arm64
• Chrome (web) • chrome • web-javascript • Google Chrome 127.0.6533.99
! Error: Browsing on the local area network for iPhone. Ensure the device is unlocked and attached with a cable or associated with the same local area network as this Mac.
The device must be opted into Developer Mode to connect wirelessly. (code -27)

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

• No issues found!

Version

8.5.0

Steps to Reproduce

Configure this in your pubspec.yaml:

dependencies:
  sentry_dio: ^8.5.0
  sentry_flutter: 8.5.0
  sentry_logging: 8.5.0

dev_dependencies:
  sentry_dart_plugin: ^2.1.0

sentry:
  project: my_project
  org: my_org
  ignore_missing: true

Then this in your android/app/build.gradle:

plugins {
//...
  id "io.sentry.android.gradle" version "4.10.0"
}

import io.sentry.android.gradle.extensions.InstrumentationFeature
import io.sentry.android.gradle.instrumentation.logcat.LogcatLevel

entry {
    uploadNativeSymbols = true
    autoUploadNativeSymbols = true
    includeNativeSources = false
    includeSourceContext = false
    tracingInstrumentation {
        enabled = true
        features = [InstrumentationFeature.DATABASE, InstrumentationFeature.FILE_IO, InstrumentationFeature.OKHTTP, InstrumentationFeature.COMPOSE]
        logcat {
            enabled = true
            minLevel = LogcatLevel.WARNING
        }
    }

    autoInstallation {
        enabled = true
    }

    ignoredBuildTypes = ["debug"]
    ignoredFlavors = ["development", "staging"]
}

Then try to make a release build with Flutter using this command:

flutter build $ARTIFACT_TYPE \
          --build-number=1 \
          --target lib/main.dart \
          --flavor production \
          --obfuscate --split-debug-info=your/obfuscation/dir/symbols \
          --extra-gen-snapshot-options=--save-obfuscation-map=your/obfuscation/dir/obfuscation_map.json \
          --dart-define=SENTRY_ENVIRONMENT=production

And you should see this error:

Running Gradle task 'bundleProductionRelease'...                
You are applying Flutter's app_plugin_loader Gradle plugin imperatively using the apply script method, which is deprecated and will be removed in a future release. Migrate to applying Gradle plugins with the declarative plugins block: https://flutter.dev/go/flutter-gradle-plugin-apply

You are applying Flutter's main Gradle plugin imperatively using the apply script method, which is deprecated and will be removed in a future release. Migrate to applying Gradle plugins with the declarative plugins block: https://flutter.dev/go/flutter-gradle-plugin-apply


FAILURE: Build failed with an exception.

* What went wrong:
Circular dependency between the following tasks:
:app:compileProductionReleaseJavaWithJavac
+--- :app:compileProductionReleaseKotlin
|    \--- :app:processProductionReleaseResources
|         \--- :app:copyFlutterAssetsProductionRelease
|              \--- :app:mergeProductionReleaseAssets
|                   \--- :app:generateSentryDebugMetaPropertiesProductionRelease
|                        \--- :app:generateSentryProguardUuidProductionRelease
|                             \--- :app:minifyProductionReleaseWithR8
|                                  +--- :app:mergeProductionReleaseGeneratedProguardFiles
|                                  |    +--- :app:compileProductionReleaseJavaWithJavac (*)
|                                  |    +--- :app:compileProductionReleaseKotlin (*)
|                                  |    \--- :app:processProductionReleaseResources (*)
|                                  +--- :app:mergeProductionReleaseJavaResource
|                                  |    \--- :app:compileProductionReleaseKotlin (*)
|                                  +--- :app:processProductionReleaseResources (*)
|                                  \--- :app:transformProductionReleaseClassesWithAsm
|                                       +--- :app:compileProductionReleaseJavaWithJavac (*)
|                                       +--- :app:compileProductionReleaseKotlin (*)
|                                       \--- :app:processProductionReleaseResources (*)
\--- :app:processProductionReleaseResources (*)

(*) - details omitted (listed previously)


* Try:
> Run with --stacktrace option to get the stack trace.
> Run with --info or --debug option to get more log output.
> Run with --scan to get full insights.

* Get more help at https://help.gradle.org

BUILD FAILED in 1m 41s
Running Gradle task 'bundleProductionRelease'...                  101.5s
Gradle task bundleProductionRelease failed with exit code 1


Build failed :|
Step 13 script `Build App` exited with status code 1

If I downgrade the gradle plugin version to 4.2.0 I don't get any errors, but this doesn't allow me to get the latest updates.

I see there's a related issue in the react native lib: getsentry/sentry-react-native#3644

Expected Result

Not getting a build error.

Actual Result

Getting the error above.

Are you willing to submit a PR?

None

@kahest
Copy link
Member

kahest commented Aug 8, 2024

Hey @feinstein thanks a lot for the great report and all the detail, we appreciate the effort. cc @markushi since you've been looking into related topics recently

@markushi
Copy link
Member

This should have been fixed for AGP 7.4+, but apparently (https://github.com/getsentry/sentry-dart/releases/tag/8.5.0) AGP 7.4.2 is being used here - let's investigate into this again.

@romtsn
Copy link
Member

romtsn commented Sep 3, 2024

@feinstein could you provide the android gradle plugin version (com.android.tools.build:gradle) that you're using?

@feinstein
Copy link
Author

Sure, I just changed the app name here:

buildscript {
    repositories {
        mavenCentral()
    }
}

plugins {
    id "com.android.application"
    // START: FlutterFire Configuration
    id 'com.google.gms.google-services'
    // END: FlutterFire Configuration
    // TODO: Check if this problem still applied to release builds:
    // There is an issue with sentry plugin version >=4.3.0 when making a release build.
    // Check issue at https://github.com/getsentry/sentry-react-native/issues/3644
    id "io.sentry.android.gradle" version "4.2.0"
}

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 new 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'
}

def keystoreProperties = new Properties()
def keystorePropertiesFile = rootProject.file('key.properties')
if (keystorePropertiesFile.exists()) {
    keystoreProperties.load(new FileInputStream(keystorePropertiesFile))
}

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

import io.sentry.android.gradle.extensions.InstrumentationFeature
import io.sentry.android.gradle.instrumentation.logcat.LogcatLevel

sentry {
    // Disables or enables the automatic configuration of Native Symbols
    // for Sentry. This executes sentry-cli automatically so
    // you don't need to do it manually.
    // Default is disabled.
    uploadNativeSymbols = true

    // Whether the plugin should attempt to auto-upload the native debug symbols to Sentry or not.
    // If disabled the plugin will run a dry-run.
    // Default is enabled.
    autoUploadNativeSymbols = true

    // Does or doesn't include the source code of native code for Sentry.
    // This executes sentry-cli with the --include-sources param. automatically so
    // you don't need to do it manually.
    // This option has an effect only when [uploadNativeSymbols] is enabled.
    // Default is disabled.
    includeNativeSources = false

    // Generates a JVM (Java, Kotlin, etc.) source bundle and uploads your source code to Sentry.
    // This enables source context, allowing you to see your source
    // code as part of your stack traces in Sentry.
    includeSourceContext = false

    // Enable or disable the tracing instrumentation.
    // Does auto instrumentation for specified features through bytecode manipulation.
    // Default is enabled.
    tracingInstrumentation {
        enabled = true

        // Specifies a set of instrumentation features that are eligible for bytecode manipulation.
        // Defaults to all available values of InstrumentationFeature enum class.
        features = [InstrumentationFeature.DATABASE, InstrumentationFeature.FILE_IO, InstrumentationFeature.OKHTTP, InstrumentationFeature.COMPOSE]

        // Enable or disable logcat instrumentation through bytecode manipulation.
        // Default is enabled.
        logcat {
            enabled = true

            // Specifies a minimum log level for the logcat breadcrumb logging.
            // Defaults to LogcatLevel.WARNING.
            minLevel = LogcatLevel.WARNING
        }
    }

    // Enable auto-installation of Sentry components (sentry-android SDK and okhttp, timber and fragment integrations).
    // Default is enabled.
    // Only available v3.1.0 and above.
    autoInstallation {
        enabled = true
    }

    ignoredBuildTypes = ["debug"]
    ignoredFlavors = ["development", "staging"]
}

android {
    namespace "my.app"
    compileSdkVersion flutter.compileSdkVersion
    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 {
        applicationId "my.app"
        minSdkVersion flutter.minSdkVersion
        targetSdkVersion flutter.targetSdkVersion
        versionCode flutterVersionCode.toInteger()
        versionName flutterVersionName
    }

    signingConfigs {
        if (System.getenv("ANDROID_KEYSTORE_PATH")) {
            release {
                storeFile file(System.getenv("ANDROID_KEYSTORE_PATH"))
                keyAlias System.getenv("ANDROID_KEYSTORE_ALIAS")
                keyPassword System.getenv("ANDROID_KEYSTORE_PRIVATE_KEY_PASSWORD")
                storePassword System.getenv("ANDROID_KEYSTORE_PASSWORD")
            }
        } else {
            release {
                keyAlias keystoreProperties['keyAlias']
                keyPassword keystoreProperties['keyPassword']
                storeFile keystoreProperties['storeFile'] ? file(keystoreProperties['storeFile']) : null
                storePassword keystoreProperties['storePassword']
            }
        }
    }

    flavorDimensions "default"
    productFlavors {
        production {
            dimension "default"
            applicationIdSuffix ""
            manifestPlaceholders = [appName: "MyApp"]
        }
        staging {
            dimension "default"
            applicationIdSuffix ".stg"
            manifestPlaceholders = [appName: "[STG] MyApp"]
        }
        development {
            dimension "default"
            applicationIdSuffix ".dev"
            manifestPlaceholders = [appName: "[DEV] MyApp"]
        }
    }

    buildTypes {
        release {
            signingConfig signingConfigs.release
        }
        debug {
            signingConfig signingConfigs.debug
        }
    }
}

flutter {
    source '../..'
}

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

@buenaflor
Copy link
Contributor

Thanks for providing this!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: No status
Status: Needs Investigation
Development

No branches or pull requests

5 participants