'Could not find protoc-3.9.2-osx on Flutter/Android build

I am working on a Flutter application which integrates a native package which uses Protobuff. I work on Android Studio and Mac (Apple ship).

On windows, the application builds, but since I work on MacOs I can no longer build the application. I get the following error:

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ‘:mypackage:generateDebugProto’.
> Could not resolve all files for configuration ‘:mypackage:protobufToolsLocator_protoc’.
   > Could not find protoc-3.9.2-osx-aarch_64.exe (com.google.protobuf:protoc:3.9.2).
     Searched in the following locations:
         https://jcenter.bintray.com/com/google/protobuf/protoc/3.9.2/protoc-3.9.2-osx-aarch_64.exe

* 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 888ms
Exception: Gradle task assembleDebug failed with exit code 1

The build on iOS doesn't work either.

How can I resolve this error? Do you have any ideas on where the problem is coming from?



Solution 1:[1]

I have found a solution based on : https://github.com/grpc/grpc-java/issues/7690

I have create file : $HOME/.gradle/gradle.properties with :

protoc_platform=osx-x86_64

My build.gradle :

protobuf {
// Configure the protoc executable
protoc {
    // for apple m1, add protoc_platform=osx-x86_64 in $HOME/.gradle/gradle.properties
    if (project.hasProperty('protoc_platform')) {
        artifact = "com.google.protobuf:protoc:3.9.2:${protoc_platform}"
    } else {
        artifact = "com.google.protobuf:protoc:3.9.2"
    }
}
plugins {
    javalite {
        // The codegen for lite comes as a separate artifact
        if (project.hasProperty('protoc_platform')) {
            artifact = "com.google.protobuf:protoc-gen-javalite:3.0.0:${protoc_platform}"
        } else {
            artifact = "com.google.protobuf:protoc-gen-javalite:3.0.0"
        }
    }
}

Solution 2:[2]

x86_64 works both on Intel and Apple chips

import org.apache.tools.ant.taskdefs.condition.Os

// Compatible with macOS on Apple Silicon
def archSuffix = Os.isFamily(Os.FAMILY_MAC) ? ':osx-x86_64' : ''

protobuf {
    protoc {
        artifact = "com.google.protobuf:protoc:3.20.1$archSuffix"
    }
    plugins {
        javalite {
            artifact = "com.google.protobuf:protoc-gen-javalite:3.0.0$archSuffix"
        }
    }
}

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Dev Loots
Solution 2