Android问题集锦(1)

注:记录自己平常工作中遇到的一些问题,以及应对这些问题的解决方案。方便自己查看,也方便他人遇到同样的问题,可以少走些弯路。

1. android studio :   no debuggable applications 

解决方案:Tools->Android->Enable ADB Integration 选中。

 

如果选中还提示no debuggable applications 的话,有可能是你自己的add没有配置。自己可以在终端用命令 add devices 查看一下。 我自己就是弄完不可以,最后才发现自己的adb配置完成后,配置文件没有立即生效导致的。

 

 

辅助说一点,adb的配置吧,首先打开terminal~

(1)cd ~

(2)touch .bash_profile 回车 ps:  touch:如果没有,则创建文件,如果有,更新一下文件时间

(3) open -e .bash_profile 回车查看文件

export PATH=${PATH}:/Users/zyh/Library/Android/sdk/platform-tools
export PATH=${PATH}:/Users/zyh/Library/Android/sdk/tools

这是我电脑上的路径。不知道路径的可以tools->Android->SDKManager

查看自己Android SDK Location 的配置路径即可~

 

(4) source .bash_profile 使配置文件生效即可。

2. 在非activity得文件里使用startActivity()函数打开具体页面。

 

Intent intent = new Intent(GlobalData.app(), MainActivity.class);
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
intent.putExtra(EXTRA_CONTROLLEE_END, true);
GlobalData.app().startActivity(intent);

示例代码是从一个控制类,打开MainActivity. 这里代码中的flag是必须的,否则会报错误。

intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);

 

3. git 今天遇到一个错误记录一下。

 

解决办法:
参考:http://www.centoscn.com/CentosBug/softbug/2014/0508/2933.html 

里面讲了三种方法,我是用第一种方法解决的。

1. 删除提示信息中,对应的行数,例如上例,需要删除/home/cobyeah/.ssh/known_hosts文件的第7行(自己亲身试验可行)。

2. 删除整份/home/cobyeah/.ssh/known_hosts文件。

3. 修改/etc/ssh/ssh_config文件的配置,以后则不会再出现此问题StrictHostKeyChecking no

UserKnownHostsFile /dev/null

4.  今天遇到一個bug: 錯错误信息如下:

 

Error:Execution failed for task ':app:packageAllDebugClassesForMultiDex'.
> java.util.zip.ZipException: duplicate entry: com/google/gson/Gson$5.class

解决方案:

 

 

compile('com.digits.sdk.android:digits:1.5.0@aar') {
    transitive = true;
    exclude module: 'gson';
}

给自己添加的包添加

 

 

exclude module: 'gson';

即可解决问题。

参考网址:http://stackoverflow.com/questions/30727582/gradle-duplicate-entry

5.  android Intent 分享: 

国外的app, whatsApp以及Instagram都没有自己的Api来完成分享,都使用的是Android的intent机制完成的。实现如下:

 

//纯文本分享  whatsApp会识别shareUrl然后会显示对应的文件。
public Intent shareTextIntent(String destext, String shareUrl) {
    Intent share = new Intent(Intent.ACTION_SEND);
    share.putExtra(Intent.EXTRA_TEXT, destext + shareUrl);
    share.setType("text/plain");
    share.setPackage(PACKAGE_WHATSAPP);
    return share;
}

WhatsApp会自动识别分享url中的内容并显示出来,很智能。

 

同理,分享图片的:

 

//包含标题,详情,以及图片的分享
public Intent shareLocalStandardIntent(String title, String description, String localImagePath) {
    Intent share = new Intent(Intent.ACTION_SEND);
    share.setType("image/*");
    Uri uri = Uri.fromFile(new File(localImagePath));
    share.putExtra(Intent.EXTRA_SUBJECT, title);
    share.putExtra(Intent.EXTRA_TEXT, description);
    share.putExtra(Intent.EXTRA_STREAM, uri);
    share.setPackage(PACKAGE_WHATSAPP);
    return share;
}

这里可以分享但是,Instagram只会显示图片,标题和描述都不显示。 whatsApp是标题不显示,描述以及图片可以显示。这个可能跟第三方app的机制有关。

 

分享视频的同理:类型换成video/*即可。文件Uri传mp4等格式的视频文件即可。

6. Androidstudio里面经常会遇到protobuf 生成的java文件会报

File size exceeds configured limit (2560000). Code insight features not available.这个错误,解决办法:

 

1.点击 Help > Edit Custom Properties。如果您之前从未编辑过 IDE 属性,Android Studio 将提示您新建一个 idea.properties 文件。点击 Yes 创建文件。
2.此时 idea.properties 文件将在 Android Studio 的编辑器窗口中打开。编辑文件以添加您自己的自定义 IDE 属性。

idea.properties:

中添加

# custom Android Studio properties
#kb
idea.max.intellisense.filesize=5000

即可。 filesize大小你自己定。更改完之后如果没有生效,需要重启一下Androidstudio。

7. android clipToPadding的使用。 

定义了ViewGroup是否将裁剪它的子View,和根据它的padding(如果padding不为0)调整任何边缘效果。这个属性的默认值是true必须是boolean值,ture或false。关联方法:setClipToPadding(boolean)。

<android.support.v7.widget.RecyclerView
        android:id="@+id/recycler_view"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:clipToPadding="false"
        android:paddingTop="10dp"/>

在向上滑动RecyclerView时,子View绘制到父View的padding里面。 

 

8. Android Stuido 3.0 的坑 

log 信息:

\app\build\intermediates\incremental\mergeDebugResources\merged.dir\values\values.xml Error:(232) resource android:attr/fontStyle notfound. Error:(232) resource android:attr/font notfound. Error:(232) resource android:attr/fontWeight notfound.

解决方案

检查 buildToolsVersion 和 compileSdkVersion 是否对得上。

9. 今天android studio 编译遇到个问题:

Failed to resolve: multidex
Open File
Failed to resolve: play-services-auth
Open File
Failed to resolve: play-services-plus
Open File

解决方案:


allprojects {

    repositories {
        //这里google()必须放在首位,否则会编译出错--解决问题的关键需要加google()
        google()
        jcenter()
    }
}

10. ScrollView  设置matchParent不生效问题。

解决方法: Try adding android:fillViewport="true"to your ScrollView

remember that android:layout_height=”fill_parent” means “set the height to the height of the parent.” This is obviously not what you want when using a ScrollView. After all, the ScrollView would become useless if its content was always as tall as itself. To work around this, you need to use the ScrollView attribute called android:fillViewport. When set to true, this attribute causes the scroll view’s child to expand to the height of the ScrollView if needed. When the child is taller than the ScrollView, the attribute has no effect.

11. android studio 编译问题:

Unexpected scopes found in folder 'C:\Users\Administrator\AndroidStudioProjects\Test\app\build\intermediates\transforms\AspectTransform\debug'. Required: SUB_PROJECTS. Found: EXTERNAL_LIBRARIES, PROJECT, SUB_PROJECTS

solution:

turn off instant  run。

12 . 使用canvas.drawRoundRect()时,解决四个圆角的线比较粗的问题.「也就是说四条边界的宽度是strokeWidth的一半」

解决方案:https://blog.csdn.net/kuaiguixs/article/details/78753149

protected void onDraw(Canvas canvas) {
    super.onDraw(canvas);
    int width = getWidth();
    int height = getHeight();
 
    mPaint.setColor(Color.BLUE);
    mPaint.setStyle(Paint.Style.STROKE);
    mPaint.setStrokeWidth(5);
    canvas.drawRoundRect(2.5f, 2.5f, width-2.5f, height-2.5f, 20, 20, mPaint);
}

完美解决问题。记录一下。

13. git忽略“.gradle”文件夹无效  

解决方案:先删除在提交, 然后在添加到.gitignore文件中,如果哦远程仓库有这个文件的话,会忽略到gitignore配置的。

git rm -r --cached .  
git add .
git commit -m "update gitignore"

 

 

 

 

 

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值