android studio最基本的学识一

android studio最基本的知识一

     最近看到身边的很多android开发程序员都在使用android studio,于是自己也下了个尝试怎么使用。其实这个开发工具在2013年我就知道了,那时由于自己太懒了,就没有使用它。现在发现如果不会使用android studio在以后的android开发中肯定是一大问题! 下面是自己在使用中遇到的问题和大家分享下。

   1。Eclipse使用习惯的程序员,在初次接触到android Studio(以下简称as)时肯定无从下手,为什么这么说呢?在Eclipse中有个工作空间(workspace)这个里面可以建立很多的Project,但是在as中如果你第一使用肯定很不习惯,发现找不到workspace。这是你可以选择这里android studio最基本的学识一的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的新手一点的分享,如果写的不好欢迎广大程序员朋友给我留言!最后希望在接触到新东西时,不要有一种不愿意接受的心理,要是第一个吃螃蟹的人,因为在程序员里面,还有很多比你厉害的人物呢,难道你们都不想去超过他们吗?一起加油吧。。。。。。android studio最基本的学识一