Android Studio使用心得
說實(shí)話 開始接觸這個(gè)工具 真的認(rèn)為非常惡心 畢竟大陸被墻? 非常多東西用起來不是非常方便 并且Eclipse轉(zhuǎn)到Android Studio還是一個(gè)跨度 廢話不多說? 以下 講下我遇到的問題
1. 安裝的時(shí)候(Setup Wizard - Download Components) 這個(gè)要下載非常長時(shí)間 甚至下載不了 (PS: 這個(gè)選擇并下載2.25G的組件是studio的一個(gè)bug,評論里有人提醒,感謝這位同學(xué)。
假設(shè)網(wǎng)速不行想跳過這步的能夠在bin文件夾的idea.properties添加一行:disable.android.first.run=true即可了。mac平臺的右鍵安裝包->Show Package Contents 就找到bin文件夾了。)
?
2.新建項(xiàng)目成功后會下載Gradle,貌似這個(gè)過程不FQ也是能夠下載,可是訪問特別慢,建議FQ下載。那么下載的Gradle到什么地方呢?? 打開C:\Users\Administrator\.gradle\wrapper\dists\gradle-1.10-all\d90a2yjknzzhpcfgm937zpcte 你會看到須要的gradle版本號 比如我的是gradle-1.10 我會去百度上搜這個(gè)下載 一大堆 下載之后把gradle-1.10-all.zip拷貝到此文件夾下(C:\Users\Administrator\.gradle\wrapper\dists\gradle-1.10-all\d90a2yjknzzhpcfgm937zpcte)
?
注:假設(shè)是導(dǎo)入一個(gè)項(xiàng)目一直處于Building 那么去改動項(xiàng)目Gradle文件夾下的gradle-wrapper.properties 文件中邊的distributionUrl 最后邊改成已經(jīng)下載的gradle版本號比如 我已經(jīng)有g(shù)radle-2.2.1-all.zip 可是沒有g(shù)radle-2.4-all.zip的 所以我會改成distributionUrl=https\://services.gradle.org/distributions/gradle-2.2.1-all.zip
?
假設(shè)導(dǎo)入項(xiàng)目之后 下載Android studio那么結(jié)束掉任務(wù) 去改動項(xiàng)目根文件夾下的build.gradle
改成你如今的版本號
?dependencies {
??????? classpath 'com.android.tools.build:gradle:1.2.2'
??????? // NOTE: Do not place your application dependencies here; they belong
??????? // in the individual module build.gradle files
??? }
?
?
3. 關(guān)于build.gradle的配置:
?? 主projectapp:
??? apply plugin: 'com.android.application'? 表示申明此project為主project
?
?dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])? 默認(rèn)不須要多解釋
compile project(':StudioKlowerBase')}? 申明主工程依賴的Library 注意拼寫規(guī)則, 名字要與你的Library名字一樣
?
buildTypes {release {minifyEnabled true(表示打包簽名的時(shí)候 是正式包 會運(yùn)行混淆代碼) proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 定義代碼混淆文件 注意:proguard-rules.pro要放在主project的文件夾下 } } 完整代碼例如以下: apply plugin: 'com.android.application'android {compileSdkVersion 19buildToolsVersion "19.1.0"defaultConfig {applicationId "com.klowerbase.test"minSdkVersion 11targetSdkVersion 19versionCode 1versionName "1.0"}buildTypes {release {minifyEnabled trueproguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'}} }dependencies {compile fileTree(dir: 'libs', include: ['*.jar'])compile project(':StudioKlowerBase') }--Library 工程的配置apply plugin: 'android-library'定義為Librarydependencies {classpath 'com.android.tools.build:gradle:1.2.2' 定義編譯的gradle版本號 }完整代碼例如以下:buildscript {repositories {mavenCentral()}dependencies {classpath 'com.android.tools.build:gradle:1.2.2'} } apply plugin: 'android-library'dependencies {compile fileTree(include: '*.jar', dir: 'libs') }android {compileSdkVersion 19buildToolsVersion "19.1.0"sourceSets {main {manifest.srcFile 'AndroidManifest.xml'java.srcDirs = ['src']resources.srcDirs = ['src']aidl.srcDirs = ['src']renderscript.srcDirs = ['src']res.srcDirs = ['res']assets.srcDirs = ['assets']}// Move the tests to tests/java, tests/res, etc...instrumentTest.setRoot('tests')// Move the build types to build-types/<type>// For instance, build-types/debug/java, build-types/debug/AndroidManifest.xml, ...// This moves them out of them default location under src/<type>/... which would// conflict with src/ being used by the main source set.// Adding new build types or product flavors should be accompanied// by a similar customization.debug.setRoot('build-types/debug')release.setRoot('build-types/release')} }
項(xiàng)目的配置 代碼例如以下// Top-level build file where you can add configuration options common to all sub-projects/modules.buildscript {repositories {jcenter()}dependencies {classpath 'com.android.tools.build:gradle:1.2.2'// NOTE: Do not place your application dependencies here; they belong// in the individual module build.gradle files} }allprojects {repositories {jcenter()} } ?解決Task '' not found in root project '***'. 方法1:刪掉.iml里的<component name="FacetManager"> ... </component> 方法2:刪掉.iml跟.idea目錄 又一次導(dǎo)入程序 經(jīng)過實(shí)驗(yàn):另外一種方法 有效 因?yàn)槲矣玫膅radle-2.2.1 項(xiàng)目結(jié)構(gòu)有些變化,例如以下截圖:<img src="https://img-blog.csdn.net/20150720130051120?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQv/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/Center" alt="" />
最后在附上一些經(jīng)常使用的快捷鍵:
Ctrl+Alt+L? 格式化代碼
Ctrl+Alt+space 代碼提示
Ctrl+Alt+O 優(yōu)化導(dǎo)入的類和包
Alt+Insert 生成代碼(如get,set方法,構(gòu)造函數(shù)等)
Ctrl+Shift+Space 自己主動補(bǔ)全代碼
Ctrl+空格 代碼提示
Ctrl+R 替換
Ctrl+Y 刪除行(ctrl+x不是刪除行。是剪切。
假設(shè)不選中,則為剪切當(dāng)行。
ths for 貌似掉線) Ctrl+D 復(fù)制行 Ctrl+/ 或 Ctrl+Shift+/? 凝視(// 或者/*...*/ )
?
?
?
?
?
?
?
??
?
?
轉(zhuǎn)載于:https://www.cnblogs.com/wzjhoutai/p/6719070.html
總結(jié)
以上是生活随笔為你收集整理的Android Studio使用心得的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Jquery学习笔记:操作form表单元
- 下一篇: Android顶部粘至视图具体解释