Eclipse 转Android Studio 常见问题小结

来源:互联网 发布:prisma算法 编辑:程序博客网 时间:2024/06/07 02:31
一,快捷键
Setting>Keymsp
可以直接把eclipse默认的大部分快捷键直接导入过来

特色快捷键:
ctrl+shift+i:查看重写方法的super方法
alt +shift+r:对某个属性,方法,类重命名
ctrl +alt + L:格式化代码
ctrl + alt + 空格:xml里面获取提示
alt + insert :提示,可以便捷弹出set get 构造
alt + enter :强转
ctrl + alt +T:弹出菜单选择包裹代码块,如try catch 

二,打包相关:
获取keystore的SHA1码(很多第三方sdk在注册时需要用到):
首先cd 到keystore的路径,然后执行:
keytool -list -keystore ztbkey.keystore
最后一个是文件名

打包:
build>Generate Signed Apk,接下来和在eclipse里类似,选store文件,密码验证

三,调试,运行:
build.gradle里面修改debug的keystore:
signingConfigs {
        debug {
            storeFile file('ztbkey.keystore')
            storePassword '123456'
            keyAlias 'handnear'
            keyPassword '123456'
        }
    }
面板上点击:
Run>选择app

四,删除项目(Module):
右键项目>Open Module Setting>"_" 删除,然后可以在面板上右键"Delete"去除项目

五,个性化设置:
1,设置代码行号始终显示:
Setting>Editor>General>Appearance>勾选 show line numbers
2,注释风格修改:
Setting>Editor>Code Style>File and Code Templates:
Templates 选择"class"
Incluses 选择 File Header
然后修改,只有新增类时,才会起作用,将旧的注释删去再重新生成则不会用注释模板
3,修改sdk,jdk路径:
File>Other setting>Default Project Stucture

六,jar包依赖:
1,将jar包拷贝到libs目录
2,add libriry 选择moudle

七,aar文件依赖:
很多开源项目有依赖github上的arr文件,例如:
compile 'com.github.ozodrukh:CircularReveal:1.1.0@aar'
如果上述依赖报错,解决反法:
1,去gitbub下载相应的aar文件
2,项目里新建libs文件夹,把aar拷贝进libs
3,build.gradle里新增:
repositories{ flatDir {  dirs 'libs' }}
把原来的依赖改为:
compile (name:'circualreveal-release', ext:'aar')
name是文件名,ext:文件格式


八,多渠道发布:build.gradle:

apply plugin: 'com.android.application'

android {
compileSdkVersion 20
buildToolsVersion "23.0.0"

packagingOptions {
exclude 'META-INF/DEPENDENCIES.txt'
exclude 'META-INF/LICENSE.txt'
exclude 'META-INF/NOTICE.txt'
exclude 'META-INF/NOTICE'
exclude 'META-INF/LICENSE'
exclude 'META-INF/DEPENDENCIES'
exclude 'META-INF/notice.txt'
exclude 'META-INF/license.txt'
exclude 'META-INF/dependencies.txt'
exclude 'META-INF/LGPL2.1'
}

//这个是解决lint报错的代码
lintOptions {
abortOnError false
}
//渠道,遍历修改manifest里面的值,供不同渠道使用,此时Manifest有个节点的value 是 "${
                                           UMENG_CHANNEL
}"
productFlavors {
HandNear{ manifestPlaceholders = [UMENG_CHANNEL: "掌宝"]}
Store360 {manifestPlaceholders = [UMENG_CHANNEL: "Store360"]}
QQ{manifestPlaceholders = [UMENG_CHANNEL: "QQ"]}
Taobao{manifestPlaceholders = [UMENG_CHANNEL: "Taobao"]}
WanDouJia{manifestPlaceholders = [UMENG_CHANNEL: "WanDouJia"]}
AnZhuo{manifestPlaceholders = [UMENG_CHANNEL: "AnZhuo"]}
AnZhi{manifestPlaceholders = [UMENG_CHANNEL: "AnZhi"]}
BaiDu{manifestPlaceholders = [UMENG_CHANNEL: "BaiDu"]}
Store163{manifestPlaceholders = [UMENG_CHANNEL: "Store163"]}
GFeng{manifestPlaceholders = [UMENG_CHANNEL: "GFeng"]}
AppChina{manifestPlaceholders = [UMENG_CHANNEL: "AppChina"]}
EoeMarket{manifestPlaceholders = [UMENG_CHANNEL: "EoeMarket"]}
Store91{manifestPlaceholders = [UMENG_CHANNEL: "Store91"]}
NDuo{manifestPlaceholders = [UMENG_CHANNEL: "NDuo"]}
}

compileOptions {
sourceCompatibility JavaVersion.VERSION_1_7
targetCompatibility JavaVersion.VERSION_1_7
}



//遍历,修改最后的名称
applicationVariants.all { variant ->
variant.outputs.each { output ->
def outputFile = output.outputFile
if (outputFile != null && outputFile.name.endsWith('.apk')) {
def fileName = outputFile.name.replace(".apk", "-${defaultConfig.versionName}.apk")
output.outputFile = new File(outputFile.parent, fileName)
}
}
}

signingConfigs {
myConfig{
storeFile file("android.keystore")
storePassword "123456"
keyAlias "android.keystore"
keyPassword "123456"
}
}

defaultConfig {
applicationId "com.jujiling.lingling"
versionName "1.2.0"
versionCode 10
minSdkVersion 11
targetSdkVersion 17
// manifestPlaceholders = [UMENG_CHANNEL: "channel_name"]
}


buildTypes {
release {
signingConfig signingConfigs.myConfig

minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-project.txt'
}
}
}

dependencies {
compile 'com.android.support:support-v4:20.0.0'
compile 'com.google.code.gson:gson:2.1'
compile files('libs/baidumapapi_v2_3_0.jar')
compile files('libs/commons-logging-1.1.3.jar')
compile files('libs/httpclient-4.3.6.jar')
compile files('libs/httpcore-4.3.3.jar')
compile files('libs/httpmime-4.3.6.jar')
compile files('libs/jxmpp-core-0.4.2-beta1.jar')
compile files('libs/jxmpp-util-cache-0.4.2-beta1.jar')
compile files('libs/LingIMModel-1.0.jar')
compile files('libs/LingModel-1.0.jar')
compile files('libs/locSDK_3.1.jar')
compile files('libs/mframework.jar')
compile files('libs/ShareSDK-Core-2.5.4.jar')
compile files('libs/ShareSDK-Facebook-2.5.6.jar')
compile files('libs/ShareSDK-QQ-2.5.4.jar')
compile files('libs/ShareSDK-QZone-2.5.4.jar')
compile files('libs/ShareSDK-ShortMessage-2.5.6.jar')
compile files('libs/ShareSDK-SinaWeibo-2.5.4.jar')
compile files('libs/ShareSDK-Wechat-2.4.1.jar')
compile files('libs/ShareSDK-Wechat-Core-2.5.4.jar')
compile files('libs/ShareSDK-Wechat-Moments-2.5.4.jar')
compile files('libs/smack-android-extensions-4.1.0.jar')
compile files('libs/smack-compression-jzlib-4.1.0.jar')
compile files('libs/smack-core-4.1.0.jar')
compile files('libs/smack-experimental-4.1.0.jar')
compile files('libs/smack-extensions-4.1.0.jar')
compile files('libs/smack-im-4.1.0.jar')
compile files('libs/smack-java7-4.1.0.jar')
compile files('libs/smack-legacy-4.1.0.jar')
compile files('libs/smack-sasl-provided-4.1.0.jar')
compile files('libs/smack-tcp-4.1.0.jar')
compile files('libs/SMSSDK-1.1.7.jar')
compile files('libs/umeng-analytics-v5.2.3.jar')
compile files('libs/universal-image-loader-1.9.2-SNAPSHOT-with-sources.jar')
compile files('libs/xpp3-1.1.2.jar')
compile files('libs/zxing.jar')
}

九,关于从Eclipse导入项目:
1:.9图片资源报错:
a,android studio资源命名更严格,比如,不能有a.xml.xml类型的命名
b,.9图一定要四个方向都有黑线,左上为拉伸区域,右下为可见区域
c,最好的处理方法是直接在编辑界面加黑线

2,导入as项目时报Error:failed to find Build Tools revision 19.0.3
<a href="install.build.tools">Install Build Tools 19.0.3 and sync project</a>:
在build.gradle里面修改编译器版本,向下兼容的
buildToolsVersion "19.1.0"



























0 0
原创粉丝点击