android log 输出行位置和方法名
public class DebugInfo extends Exception {
public int line() {
StackTraceElement[] trace = getStackTrace();
if (trace == null || trace.length == 0) {
return -1;
}
return trace[0].getLineNumber();
}
public String fun() {
StackTraceElement[] trace = getStackTrace();
if (trace == null || trace.length == 0) {
return "";
}
return trace[0].getMethodName();
}
public DebugInfo() {
super();
}
@Override
public String toString() {
return line() + "|" + fun() + "|";
}
}
在这里讲上述的代码,放到android studio的module中,这样,就可以导出jar包,其他的代码中也可以使用。
android studio 导出jar包
在编译完现在的工程后,会在代码下module目录下生成
\util\build\intermediates\bundles\release\class.jar
注:util就是现在工程的module名字,
拿到了jar包,这时可以讲class.jar改成你需要名字。在其他的工程中导入jar包就可以了。
android studio 导入jar包
右击app –>Open Module Setting ->app->dependencied下,添加需要的jar包
代码工程已上传 github