一、一些问题处理
1、android studio gradle新建项目编译报错:
Error:Execution failed for task ':app:preDebugAndroidTestBuild'.> Conflict with dependency 'com.android.support:support-annotations' in project ':app'. Resolved versions for app (26.1.0) and test app (27.1.1) differ. See https://d.android.com/r/tools/test-apk-dependency-conflicts.html for details.
在app下的build.gradle中添加:
configurations.all {
resolutionStrategy.force 'com.android.support:support-annotations:27.1.1'
}
2、Error:In <declare-styleable> FontFamilyFont, unable to find attribute android:font
升级sdk:
compileSdkVersion 27
buildToolsVersion '27.0.1'
targetSdkVersion 27
3、Error:In <declare-styleable> FontFamilyFont, unable to find attribute android:fontVariationSettings
configurations.all {
resolutionStrategy {
force 'com.android.support:support-v4:27.1.0'
}
}
二、增加一个可以在第三方app中获取到的,事先定好的参数:
app的build.gradle中添加:
buildTypes {
release {
resValue "string", "test_str", "true"
}
debug {
resValue "string", "test_str", "false"
}
}
AndroidManifest.xml中添加
<application>标签下
<meta-data android:name="MY_META" android:value="@string/test_str"/>
在第三方app的代码中:
ApplicationInfo tempInfo = mContext.getPackageManager().getApplicationInfo("com.test.ty", PackageManager.GET_META_DATA);
String value = tempInfo.metaData.getString("MY_META");//为null说明未定义该参数
("com.test.ty"是含有该参数的app的包名)
三、android studio怎么显示崩溃错误,不要被其它信息刷屏:
1、切到LogCat窗口
2、在右侧的过滤输入框内输入FATA
四、在一个android studio窗口中打开多个项目——项目和项目引用的公共库:
我们通常一个窗口就打开一个项目,不太方便。怎么把项目和它引用的库都在一个窗口中打开呢?
测试过程如下:
在App项目里面新建一个library(testlib)供测试用File->New->New Module->Android Library
把新建的library项目拷贝出来和apk项目(MyApplication)同级作为公用的library——这里是测试用
在假设的第三方MyApplication项目(需要使用这个库的项目)中修改settings.gradle文件:
include ':testlib'
def path = '../testlib'
project(":testlib").projectDir = new File(path)
//如果其中有多个Module,可以include ':testlib:library1'
修改MyApplication项目下的build.gradle文件:
dependencies {
compile project(':testlib')
}
这样重新打开MyApplication项目时,就可以看到as编译器同时打开了testlib项目,编译运行没有问题。
五、 android studio的常用技巧方法
跳转到定义:Ctrl+鼠标单击
设置比较快速的编译运行调试:File->Settings->Instant run 选中“Enable Instan Run to hot swap..........”
查找:Edit->Find->Find in Path
回到前一个位置:Ctrl+Alt+向左的箭头(避免被其它应用占用)
弹出自动导入需要的包的提示:选中为找到定义的内容-》Alt+Enter
添加书签:鼠标单击要添加书签的地方,按F11 此时点击右下方的Favorites 可以看到窗口里出现Bookmarks, 展开Bookmarks可以看到刚刚添加的书签,点击书签可以快速定位。
未完,待续。。。。