android studio最基本的知識一
最近看到身邊的很多android開發程式員都在使用android studio,於是自己也下了個嘗試怎麼使用。其實這個開發工具在2013年我就知道了,那時由於自己太懶了,就沒有使用它。現在發現如果不會使用android studio在以後的android開發中肯定是一大問題! 下面是自己在使用中遇到的問題和大家分享下。
1。Eclipse使用習慣的程式員,在初次接觸到android Studio(以下簡稱as)時肯定無從下手,為什麼這麼說呢?在Eclipse中有個工作空間(workspace)這個裡面可以建立很多的Project,但是在as中如果你第一使用肯定很不習慣,發現找不到workspace。這是你可以選擇這裡的Project或者android(選擇android後as會合并res中的檔案夾)。在Scopes下面還有好幾個選項,讀者自己試試就會明白的。
2。build.gradle檔案我在第一次接觸到as時就看了很多的關於gradle的介紹,都沒有解決我所的問題。以下是預設的build.gradle檔案
buildscript { repositories { jcenter() } dependencies { classpath 'com.android.tools.build:gradle:1.0.0' // NOTE: Do not place your application dependencies here; they belong // in the individual module build.gradle files }}allprojects { repositories { jcenter() }}如果在一個項目裡的build.gradle中的dependencies 添加這樣的代碼
compile 'com.android.support:appcompat-v7:21.0.3' compile 'com.squareup.dagger:dagger:1.2.2' compile 'com.squareup.dagger:dagger-compiler:1.2.2' compile 'com.jakewharton:butterknife:6.0.0' compile 'com.squareup.retrofit:retrofit:1.9.0' compile 'com.android.support:support-v4:21.0.3' compile 'com.android.support:appcompat-v7:21.0.3'
前提是你的網可以訪問到國外的網路,不然你的項目在gradle不成功,會報錯(注意如果你的配置和上面的一模一樣在使用compile時需要能訪問到國外網路)。當然還有另外一個辦法如下
buildscript { repositories { mavenCentral() maven{ url file://E:/githubrepo/releases } //或者使用指定的遠程maven庫 maven{ url http://mvnrepository.com/ } } dependencies { classpath 'com.android.tools.build:gradle:1.0.0' // NOTE: Do not place your application dependencies here; they belong // in the individual module build.gradle files }}allprojects { repositories { mavenCentral() }}把上面的jcenter改為mavenCenter,並且加上url就不需要訪問到國外網路了,輕鬆解決。
以上就是我為剛接觸到as的新手一點的分享,如果寫的不好歡迎廣大程式員朋友給我留言!最後希望在接觸到新東西時,不要有一種不願意接受的心理,要是第一個吃螃蟹的人,因為在程式員裡面