曦远 (DealiAxy)一份私人的文字刊物

StarBlog
返回文章列表折页手记阅读全文
Android开发

Android Development: A Record of Wrestling with Gradle

Preface A bit annoying. I recently upgraded my computer, adding RAM and an SSD, but the new RAM wasn't very compatible and caused frequent crashes. After I went to the seller and swapped the RAM stick, it was fine, but that also led me to rashly reinstall the system = =... I had some files on the system drive that I forgot to save, so they were lost. I only finished setting up the new system this afternoon, so I haven't been able to write posts these past two days. (Gotta say Chrome is really useful; the sync feature saved me a lot of trouble.) First, a rant about Gradle Downsides: it eats a lot of resources, is slow, and the network is even worse when using it in China. This

曦远 (DealiAxy)约 7 分钟
目录4 个章节

Preface

A bit annoying. I recently upgraded my computer, adding RAM and an SSD, but the new RAM wasn't very compatible and caused frequent crashes. After I went to the seller and swapped the RAM stick, it was fine, but that also led me to rashly reinstall the system = =... I had some files on the system drive that I forgot to save, so they were lost. I only finished setting up the new system this afternoon, so I haven't been able to write posts these past two days. (Gotta say Chrome is really useful; the sync feature saved me a lot of trouble.)

First, a rant about Gradle

Downsides: It eats a lot of resources, is slow, and the network is even worse when using it in China. This afternoon while setting up the environment, this thing wasted a ton of my time. At first the Gradle files wouldn't download; after I downloaded them manually, the dependency packages wouldn't download. I was so done. I spent ages hunting for mirrors and downloading things by hand and still couldn't get it working. (No experience.) You ask why I didn't use a proxy?? What? I did set a SOCKS proxy, but it completely ignored me—the places that wouldn't download still wouldn't download, and the Maven repos still didn't work. I won't ramble on any further; here's the solution: The correct way to set a proxy is like this—edit gradle.properties:

Location of this file: Linux/Mac: ~/.gradle/gradle.properties Windows: C:\Users\你的用户名\.gradle\gradle.properties

I'll eat my words if setting a SOCKS proxy actually works. Also, you MUST set https!

systemProp.http.proxyHost=127.0.0.1
systemProp.http.proxyPort=1080
systemProp.https.proxyHost=127.0.0.1
systemProp.https.proxyPort=1080

After setting the proxy, run ./gradlew build in the Project Root and there shouldn't be much of a problem. If there are errors, just follow the messages to fix them. I prefer using the command line; it's more straightforward than an IDE.

Optimizing Gradle Speed

Gradle's poor performance is well known. How to fix it? Throw hardware at it, you want to get stronger without paying? Enough talk—just edit this gradle.properties:

org.gradle.daemon=true
org.gradle.parallel=true
org.gradle.configureondemand=true
org.gradle.jvmargs=-Xmx2048m -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8

And also configure it in the IDE:

emmmm

Yeah, that's about it for this Gradle configuration. Now I get a bit anxious whenever I see that word—somehow it brings back the fear of being dominated by Gradle. I'm out~

_EOF_

Android Development: A Record of Wrestling with Gradle

本文作者:
程序设计实验室
版权声明:
本博客所有文章除特别声明外,均采用 BY-NC-SA 许可协议。转载请注明出处!

相关文章

该死的应用闪退,终于解决error-while-inflating-CardView

前言 (先来一个微笑脸)这个问题已经困扰我好久了,之前各种搜索无果,得到的解决方案无非就是 AppCompact 和 CardView 包的版本不一样云云,然而我根本没有这个问题。(怕是不把我Gradle看在眼里?) 问题 就是这么个界面,用到了RecycleView和Cardview,但是在SDK 23以下都不行,官方已经写明这个组件是支持到SDK9还是10的,反正基本是个android手机就可

2022-08-22 · Android开发 · 约 1 分钟

讨论

共 0 条

良言一句三冬暖,恶语伤人六月寒。

加载评论中…