開(kāi)篇廢話
Android開(kāi)發(fā)使用Mac Apple M1 + protobuf時(shí)報(bào)Could not resolve all files for configuration ':app:protobufToolsLocator_protoc'. Could not find protoc-osx-aarch_64.exe
遇到的問(wèn)題
今天換了MacBook Air筆記本進(jìn)行開(kāi)發(fā),非常開(kāi)心,因?yàn)殡娔X配置很高谒拴,但是隨之而來(lái)了一個(gè)問(wèn)題泡态,之前好好的代碼怎么跑不起來(lái)了,反而報(bào)了下面這樣的錯(cuò)誤葫笼。
Execution failed for task ':app:generateDebugProto'.
> Could not resolve all files for configuration ':app:protobufToolsLocator_protoc'.
> Could not find protoc-3.6.1-osx-aarch_64.exe (com.google.protobuf:protoc:3.6.1).
Searched in the following locations:
https://repo.maven.apache.org/maven2/com/google/protobuf/protoc/3.6.1/protoc-3.6.1-osx-aarch_64.exe
Possible solution:
- Declare repository providing the artifact, see the documentation at https://docs.gradle.org/current/userguide/declaring_repositories.html
開(kāi)始解決
簡(jiǎn)單一看搞疗,不就是找不到某個(gè)庫(kù),下載不下來(lái)了嘛配椭,是不是代理的問(wèn)題,是不是要換一下maven倉(cāng)庫(kù)雹姊,倒騰了半天股缸,發(fā)現(xiàn)事情并不簡(jiǎn)單,其它同事從來(lái)沒(méi)遇到過(guò)這樣的問(wèn)題吱雏,只有我換了新電腦遇到了敦姻,而新電腦的CPU是ARM架構(gòu)的瘾境,看來(lái)只能去官方和github找找答案了。
github protobuf issues
protoc {
artifact = if (project.hasProperty("protocPlatform")) {
"com.google.protobuf:protoc:${protobuf_version}:osx-x86_64"
} else {
"com.google.protobuf:protoc:${protobuf_version}"
}
}
從代碼來(lái)猜測(cè)镰惦,如果我們的CPU是Apple M1的話迷守,我們就使用添加:osx-x86_64
后綴,不同的架構(gòu)下去使用不同的編譯器旺入。
再次遇到問(wèn)題
我在我的電腦上發(fā)現(xiàn)并沒(méi)有解決問(wèn)題兑凿,但是當(dāng)時(shí)提問(wèn)的人應(yīng)該是解決了問(wèn)題了,是不是方法更新了茵瘾,如果小伙伴們用上面的方法就解決了礼华,就不用往下看了。
再次解決問(wèn)題
最終我從protobuf的使用場(chǎng)景之一的grpc的github找到了解決辦法拗秘。
github grpc issues
protobuf {
protoc {
if (osdetector.os == "osx") {
artifact = 'com.google.protobuf:protoc:${protobuf_version}:osx-x86_64'
} else {
artifact = 'com.google.protobuf:protoc:${protobuf_version}'
}
}
}
用上面的方法圣絮,最終解決了我的問(wèn)題,其核心只不過(guò)是判斷是否是osx
的方式變了雕旨。
寫(xiě)在最后
如果解決了大家的問(wèn)題扮匠,希望大家可以給我點(diǎn)個(gè)贊,您的支持是我創(chuàng)作的最大的動(dòng)力凡涩。