Android Studio missing Subversion plugin
Please make sure that the “SubversionIntegration” plugin is enabled in Preferences > Plugins
检查下是否多次引用同一个jar包
以下情况
1. module下jar包版本不同
同一个module 在libs中包含乐.jar,而在src下又把相应的source页加入了
gradle中是否重复编译,
比如
已经加了compile fileTree(include: [‘*.jar’], dir: ‘libs’)
然而在下面又加一句compile files(‘libs/xxx.jar’)
参考 Error:Execution failed for task ‘:app:dexDebug’. com.android.ide.common.process.ProcessException
在使用Handler更新UI的时候public class SampleActivity extends Activity {
private final Handler mLeakyHandler = new Handler() {
@Override
public void handleMessage(Message msg) {
// TODO
}
}
}会包上述warning 会导致内存泄露
原因在于匿名内部类handler持有activity的引用,当activity finish后 handler还没有处理完,导致activity的view和resource资源不能得到释放,导致内存泄露
针对这个问题google官方给出了正确的做法
通过静态内部类 包含activity的弱引用来处理。
public class SampleActivity extends Activity {
/**
* Instances of static inner classes do not hold an implicit
* reference to their outer class.
*/
private static class MyHandler extends Handler {
private final WeakReference mActivity;
public MyHandler(SampleActivity activity) {
mActivity = new WeakReference(activity);
}
@Override
public void handleMessage(Message msg) {
SampleActivity activity = mActivity.get();
if (activity != null) {
// ...
}
}
}
private final MyHandler mHandler = new MyHandler(this);
/**
* Instances of anonymous classes do not hold an implicit
* reference to their outer class when they are “static”.
*/
private static final Runnable sRunnable = new Runnable() {
@Override
public void run() { }
};
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// Post a message and delay its execution for 10 minutes.
mHandler.postDelayed(sRunnable, 60 * 10 * 1000);
// Go back to the previous Activity.
finish();
}
}
参考android handler的警告Handler Class Should be Static or Leaks Occur
For Windows/Linux, you can go to File -> Settings -> Editor -> General -> Auto Import -> Java and make the following changes:
change Insert imports on paste value to All
markAdd unambigious imports on the fly option as checked
On a Mac, do the same thing in Android Studio -> Preferences
参考What is the shortcut to Auto import all in Android Studio?
/home/cenuser/android/android-ndk-r7b/build/core/build-local.mk:130: *** Android NDK: Aborting . Stop.
cd到jni目录。或者 ndk-build -C your_project_path
Make a bundle object and insert your data (in this example your Category object). Be careful, you can't pass this object directly into the bundle, unless it's serializable. I think it's better to build your object in the fragment, and put only an id or something else into bundle. This is the code to create and attach a bundle:
Bundle args = new Bundle();
args.putLong("key", value);
yourFragment.setArguments(args);
After that, in your fragment access data:
Type value = getArguments().getType("key");
That's all.
find -type d -name '.svn' -exec rm -rfv {} \;
参考 http://blog.csdn.net/zhaoyu7777777/article/details/9445717
git配置使用,已经把公钥发给发给服务端,在终端命令行也是可以正常的pull push,但是在androidstudio push或者pull的时候确出现上述错误
解决方式
setting –> Version Control –>Git ,In the SSH executable dropdown, choose Native
keytool -list -keystore xxx.keystore
eg:查看debug.keystore
keytool -list -keystore ~/.android/debug.keystore
通过brew安装,相当于ubuntu中得apt-get
首先安装brew
curl -LsSf http://github.com/mxcl/homebrew/tarball/master | sudo tar xvz -C/usr/local –strip 1
然后就可以使用brew安装软件了
比如 使用brew安装软件 brew install wget
java.io.IOException: Can’t read [/libs/xxx.jar] (No such file or directory)
http://stackoverflow.com/questions/26028171/android-studio-proguard-java-io-ioexception-bin-classes-no-such-file-or-d
解答 proguard-android.txt文件中不用在指定 -injars, -outjars, or -libraryjars or libs.
The Android Gradle plugin already specifies all input and output for you, so you must not specify -injars, -outjars, or -libraryjars.
Moreover, the file proguard-android.txt in the Android SDK specifies all generic Android settings for you, so you shouldn’t specify them again.
Essentially, your file proguard-rules.txt can be empty, except for any application-specific settings to make sure any reflection continues to work
解决方法 :
第一步:
android:button=”@null”这条语句将原来系统的RadioButton图标给隐藏起来。
第二步:
android:drawableRight=”@android:drawable/btn_radio”这条语句
参考 http://blog.csdn.net/sunnyfans/article/details/7901592
众所周知,在跨程序的工程中,统一编码是至关重要的,而目前最普遍的则是统一采用“utf8”编码方案。
但是在采用utf8方案的时候,请注意编辑器的自作聪明。
比如editplus。
原因就在于某些编辑器会往utf8文件中添加utf8标记(editplus称其为签名),它会在文件开始的地方插入三个不可见的字符(0xEF 0xBB 0xBF,即BOM),它的表示的是 Unicode 标记(BOM)。
参考 http://hyl198611.iteye.com/blog/1336981
解决方式,需要remount /system
mount -o remount,rw /system
XXX\src\main\assets
public class MainActivity extends Activity {
private Toast toast;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
toast = Toast.makeText(getApplicationContext(), "确定退出?", 0);
}
public void onBackPressed() {
quitToast();
}
private void quitToast() {
if(null == toast.getView().getParent()){
toast.show();
}else{
System.exit(0);
}
}
}
或者
private Toast toast;
protected void onCreate(Bundle savedInstanceState) {
...
toast = Toast.makeText(this, "再按一次退出应用", Toast.LENGTH_SHORT);
toast.setGravity(Gravity.BOTTOM, 0, ConversionUtil.dip2px(this, 150));
}
@Override
public void onBackPressed() {
if (doubleBackToExitPressedOnce) {
if(toast!=null){
toast.cancel();
}
super.onBackPressed();
return;
}
this.doubleBackToExitPressedOnce = true;
toast.show();
new Handler().postDelayed(new Runnable() {
@Override
public void run() {
doubleBackToExitPressedOnce=false;
}
}, 2000);
}
参考 Android关于双击退出应用的问题
android.view.InflateException: Binary XML file line #17: Error inflating class android.support.design.internal.NavigationMenuView
Caused by: java.lang.reflect.InvocationTargetException
Caused by: android.content.res.Resources$NotFoundException: Resource is not a Drawable (color or path): TypedValue{t=0x2/d=0x7f0100c5 a=-1}
You need to use a Theme.AppCompat theme (or descendant) with this activity.
解决方法 :使用NavigationMenuView的Activity【一般都是mainActivity】继承自AppCompatActivity,并且修改AndroidManifest.xml中对应activity的theme,使用继承自@style/Theme.AppCompat的主题。
public class AccessKeyValueOfHashMap {
public static void main(String[] args) {
// Create a Empty HashMap
HashMap obHashMap = new HashMap();
// Put values in hash map
obHashMap.put("AB", "1");
obHashMap.put("EF", "2");
obHashMap.put("Gh", "3");
obHashMap.put("CD", "4");
//Store entry (Key/Value)of HashMap in set
Set mapSet = (Set) obHashMap.entrySet();
//Create iterator on Set
Iterator mapIterator = mapSet.iterator();
System.out.println("Display the key/value of HashMap.");
while (mapIterator.hasNext()) {
Map.Entry mapEntry = (Map.Entry) mapIterator.next();
// getKey Method of HashMap access a key of map
String keyValue = (String) mapEntry.getKey();
//getValue method returns corresponding key's value
String value = (String) mapEntry.getValue();
System.out.println("Key : " + keyValue + "= Value : " + value);
}
}
}
android:imeOptions="actionSend"
android:inputType="text"
去掉下划线只需把背景设置成为“@null”,
如果想设为其他样式也是设置背景
latest version of the NDK (right now it's r10e)
Application.mk
APP_ABI := armeabi arm64-v8a armeabi-v7a x86 mips
You can fix this cleanly with a single line in Application.mk (docs):
APP_CFLAGS += -DSTDC_HEADERS
This has been updated to reflect the release of API 21, Lollipop. Be sure to download the latest SDK.
In one of my modules I had the following in build.gradle:
dependencies {
compile 'com.android.support:support-v4:+'
}
Changing this to
dependencies {
// do not use dynamic updating.
compile 'com.android.support:support-v4:21.0.0'
}
fixed the issue.
参考Manifest merger failed : uses-sdk:minSdkVersion 14
修改了build.gradle中的gradle
也要修改gradle-wrapper.properties
例如:
build.gradle
dependencies {
classpath 'com.android.tools.build:gradle:1.2.3'
}
gradle-wrapper.properties
distributionUrl=https\://services.gradle.org/distributions/gradle-2.4-all.zip
android {
compileSdkVersion 21
buildToolsVersion "21.1.0"
defaultConfig {
...
minSdkVersion 14
targetSdkVersion 21
...
// Enabling multidex support.
multiDexEnabled true
}
...
}
dependencies {
compile 'com.android.support:multidex:1.0.0'
}
http://stackoverflow.com/questions/25477860/error-inflating-class-android-support-v7-widget-recyclerview
http://stackoverflow.com/questions/11753719/how-do-i-properly-extend-a-layout-class
http://stackoverflow.com/questions/6056564/installation-error-install-parse-failed-manifest-malformed
I was having this error because i had capital letters in my package name like this
Com.Example.packagename
after i had changed it to something like
com.example.packagename
it was solved
RelativeLayout中存在循环的相关
首先正确使用 google的multipartdex
android {
compileSdkVersion 21
buildToolsVersion "21.1.0"
defaultConfig {
...
minSdkVersion 14
targetSdkVersion 21
...
// Enabling multidex support.
multiDexEnabled true
}
...
}
dependencies {
compile 'com.android.support:multidex:1.0.0'
}
修改Application.两种方法:
1) 直接把Application替换成MultiDexApplication
"1.0" encoding="utf-8"?>
"http://schemas.android.com/apk/res/android"
package="com.example.android.multidex.myapplication">
"android.support.multidex.MultiDexApplication">
...
2) 在原来的Application中修改调用MultiDex.install(this);
public class HelloMultiDexApplication extends Application {
@Override
public void onCreate() {
super.onCreate();
}
@Override
protected void attachBaseContext(Context base) {
super.attachBaseContext(base);
MultiDex.install(this);
}
}
如果做了上面处理,依旧NoClassDefFound error 通过如下方式处理:
一些在二级Dex加载之前,可能会被调用到的类(比如静态变量的类),需要放在主Dex中.否则会ClassNotFoundError.
通过修改Gradle,可以显式的把一些类放在Main Dex中.
参考Android 分Dex (MultiDex)
sudo apt-get install libc6:i386 libncurses5:i386 libstdc++6:i386 lib32z1
Android TabLayout,当tab总宽度少于一屏时候,扩展为屏幕宽度展示.当tab总宽度大于一屏时,滚动显示
Tab gravity only effects MODE_FIXED.
One possible solution is to set your layout_width to wrap_content and layout_gravity to center_horizontal:
id="@+id/sliding_tabs"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
app:tabMode="scrollable" />
If the tabs are smaller than the screen width, the TabLayout itself will also be smaller and it will be centered because of the gravity. If the tabs are bigger than the screen width, the TabLayout will match the screen width and scrolling will activate.
参考Android Support Design TabLayout: Gravity Center and Mode Scrollable
目前采用的方案是,在AndroidManifest.xml文件中配置
"UMENG_CHANNEL"
android:value="${UMENG_CHANNEL_VALUE}" />
在app的build.gradle文件中配置
android{
//用于生成不同渠道号
productFlavors {
wandoujia {}
baidu {}
yingyongbao{}
...
}
productFlavors.all {
flavor -> flavor.manifestPlaceholders = [UMENG_CHANNEL_VALUE: name]
}
}
这样编译时会生成对应的渠道包apk.现在问题来了,如果有几十个渠道,会生成对应几十个apk包.打包编译一个apk一般需要1分钟左右(和电脑配置有关).那么打包几十个要几十分钟的时间.确实挺费时间的.那么有没有好的方式呐?
当然是有的
我们可以采用如下方案处理.通过文件配置只需要生成一个apk包
此种方法是需要创建文件的。
我们在写完我们的代码之后,在app/src下面,分别创建和main同级目录的文件夹umeng, wandoujia, yingyongbao,这三个文件夹里面都各只有一个AndroidManifest.xml文件,文件只需要如下:
[plain] view plain copy 在CODE上查看代码片派生到我的代码片
"http://schemas.android.com/apk/res/android"
package="your.package.name">
"UMENG_CHANNEL" android:value="UMENG"/>
注意,上面的value的值要和你的渠道名所对应。比如wandoujia里面要对应为你豌豆荚上的渠道名(如WANDOUJAI)。
然后在你的build.gradle的android{}节点里面,添加productFlavors节点,代码如下:
[plain] view plain copy 在CODE上查看代码片派生到我的代码片
android {
// 这里是你的其他配置
productFlavors{
umeng{ }
wandoujai { }
yingyongbao{ }
}
// 你的其他配置
}
注意这里的flavors的名字要和你的文件夹的名字对应。这样配置之后,构建的就是多渠道的APK了。
参考
Gradle实现的两种简单的多渠道打包方法
有些模拟器比如genymotion自带了tcpdump,如果没有的话,需要下载tcpdump:
http://www.strazzere.com/android/tcpdump
把tcpdump push到/data/local下,抓包命令:
Linux抓包工具tcpdump详解
很多开发者服务都需要绑定签名信息,用下面的命令可以查看签名:
keytool -list -v -keystore release.jks
这个一般用于提示信息对话框,如果文字是一行就居中,多行就居左。
在TextView外套一层wrap_content的ViewGroup即可简单实现:
网上一大堆setCompoundDrawables()方法无效不显示的问题,然后解决方法是setBounds,需要计算大小…
不用这么麻烦,用setCompoundDrawablesWithIntrinsicBounds()这个方法最简单!
以前做ROM的时候经常碰到一些第三方软件(某音乐APP)下载了新文件或删除文件之后,但是媒体库并没有更新,因为这个是需要第三方软件主动触发。
大家都知道,跑monkey的参数设置有一些要注意的地方,比如太快了不行不切实际,太慢了也不行等等,这里给出一个参考:
一边跑monkey,一遍抓log吧。
dumpsys可以查看系统服务和状态,非常强大,可通过如下查看所有支持的子命令:
这里列举几个稍微常用的:
媒体库会在手机启动,SD卡插拔的情况下进行全盘扫描,不是实时的而且代价比较大,所以单个文件的刷新很有必要。
注[278-284来源于]
你应该知道的那些Android小经验
比如:
"1.0" encoding="utf-8"?>
"http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/rootView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center">
"@+id/progress_loading"
android:layout_width="75dp"
android:layout_height="60dp"/>
"@+id/tv_reload"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@android:color/transparent"
android:src="@drawable/refresh_big"
android:scaleType="centerInside"
android:visibility="gone"
tools:text="点我,重新加载"
tools:visibility="visible"/>
加填充xml文件时,TextView是隐藏的,但又想在xml中直观的看到它显示后的整体效果.借助xmlns:tools=”http://schemas.android.com/tools” 完美实现.
参考android中xml tools属性详解
Spellchecker inspection helps locate typos and misspelling in your code, comments and literals, and fix them in one click
android studio对于错误拼写/不识别的英文单词,给予波浪提示
选中单词,单击鼠标右键 spelling
Save ‘xxx’ to dictionary..
Package names are written in all lower case to avoid conflict with the names of classes or interfaces.
包名小写,避免和类名或接口名冲突
android {
defaultConfig {
ndk {
moduleName "your_module_name"
ldLibs "log"
}
}
}
参考undefined reference to `__android_log_print’
更多问题请关注 android开发遇到问题点滴