日常问题解决记录

指令配置相关

Git相关

撤销commit

1.git reset HEAD^ 撤销最后一次commit

查看远端仓库地址

2.git remote -v 查看远端仓库地址

1
2
3
chenyulong01$ git remote -v
origin https://github.com/danengz/OpenCVDemo.git (fetch)
origin https://github.com/danengz/OpenCVDemo.git (push)

git stash

1
2
3
4
5
6
7
chenyulong01$ git stash list
stash@{0}: On f-jy-10.16.0-teg-video-cyl: 接入teg video
chenyulong01$ git stash clear
chenyulong01$ git stash save "接入teg video-jiaoyou"
chenyulong01$ git stash pop
chenyulong01$ git stash apply 0
chenyulong01$ git stash apply stash@{0}

Linux下Git命令中文显示乱码

提示异常:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
Changes not staged for commit:
(use "git add <file>..." to update what will be committed)
(use "git checkout -- <file>..." to discard changes in working directory)

modified: "\347\211\210\346\234\254\347\256\241\347\220\206/.DS_Store"

Untracked files:
(use "git add <file>..." to include in what will be committed)

"\347\211\210\346\234\254\347\256\241\347\220\206/\350\264\250\351\207\217\344\277\235\350\257\201/\346\265\213\350\257\225\347\224\250\344\276\213\351\233\206/\346\224\257\344\273\230\347\233\270\345\205\263.numbers"

no changes added to commit (use "git add" and/or "git commit -a")

chenyulong01deMacBook-Pro:WbuDoc chenyulong01$ git config --global core.quotepath false
chenyulong01deMacBook-Pro:WbuDoc chenyulong01$ git status
On branch master
Your branch is up-to-date with 'origin/master'.

Changes not staged for commit:
(use "git add <file>..." to update what will be committed)
(use "git checkout -- <file>..." to discard changes in working directory)

modified: .DS_Store
modified: 版本管理/.DS_Store

Untracked files:
(use "git add <file>..." to include in what will be committed)

解决方案: git config –global core.quotepath false

github token

Mac修改网址
在钥匙串中搜索github.com,点显示密码:修改密码改成token即可:

1
chenyuddddeMacBook-Pro:nunu03.github.io chenxxx$ git remote set-url origin https://ghp_fGtnlW3RO2ncOdCwi1UVNStf9l3eSE2Jjsdsfsd@github.com/chesdsd/nunu03.github.io.git/

gradle相关

查看Gradle Task对应源码类

1
2
3
4
5
6
7
8
9
10
11
chenyulong01$ ./gradlew -q help --task app:mergeReleaseResources
Detailed task information for app:mergeReleaseResources
Path
:app:mergeReleaseResources
Type
MergeResources (com.android.build.gradle.tasks.MergeResources)
Description
-
Group
-
chenyulong01deMacBook-Pro:MyActivityTest chenyulong01$

bash: ./gradlew: Permission denied

1
chmod +x gradlew

sdkman

安装groovy

Simply open a new terminal and enter:
$ curl -s get.sdkman.io | bash
Follow the instructions on-screen to complete installation.
Open a new terminal or type the command:
$ source “$HOME/.sdkman/bin/sdkman-init.sh”
Then install the latest stable Groovy:
$ sdk install groovy
After installation is complete and you’ve made it your default version, test it with:
$ groovy -version
That’s all there is to it!

配置路径使idea容易找到

sudo ln -s /usr/local/opt/groovy/libexec /Library/Groovy

安装目录

所有sdk都安装在了sdkman目录下:~/.sdkman/candidates/
sdkman介绍

Mac系统如何显示隐藏文件?

Command+Shift+. 可以显示隐藏文件、文件夹,再按一次,恢复隐藏;

Linux/Mac下统计当前文件夹下的文件个数、目录个数

1.统计当前文件夹下文件的个数

ls -l |grep "^-"|wc -l

2、 统计当前文件夹下目录的个数

ls -l |grep "^d"|wc -l

3、 统计当前文件夹下文件的个数,包括子文件夹里的

ls -lR|grep "^-"|wc -l

4、统计文件夹下目录的个数,包括子文件夹里的

ls -lR|grep "^d"|wc -l

5、 说明

代码如下:

ls -l

长列表输出当前文件夹下文件信息(注意这里的文件,不同于一般的文件,可能是目录、链接、设备文件等)

代码如下:

grep "^-"

这里将长列表输出信息过滤一部分,只保留一般文件,如果只保留目录就是 ^d
代码如下:

wc -l

统计输出信息的行数,因为已经过滤得只剩一般文件了,所以统计结果就是一般文件信息的行数,又由于一行信息对应一个文件,所以也就是文件的个数。

adb backup

1.备份:adb backup -f /Users/xxx/Desktop/photo/clientbackup.ab 包名
2.Android backup extractor
下载abe.jar
执行: java -jar /Users/xxx/Desktop/photo/abe.jar unpack /Users/xxx/Desktop/photo/clientbackup.ab /Users/xxx/Desktop/photo/clientbackup.tar
3.恢复:adb restore clientbackup.ab

adb多用户操作

查看用户列表

adb shell pm list users

创建新用户

adb shell pm create-user [–profileOf USER_ID] [–managed] USER_NAME

adb shell pm create-user 10 godv

启动和切换用户

adb shell am switch-user USER_ID

adb shell am start-user USER_ID

安装应用到某个用户下

adb install –user USER_ID name.apk

删除用户

adb shell pm remove-user USER_ID

为了多用户下的数据安全性,在每个新用户创建之初,不管是外部存储(External Storage)还是app data目录,Android都为其准备了独立的文件存储

/storage/emulated/下拥有不同的用户分区

/storage/emulated/0

/storage/emulated/10

代码查看不同用户 以SDK为例 反射获取

1
2
3
4
5
6
7
8
int uid = -1;
try {
Class clz = Class.forName("android.os.UserHandle");
Method m = clz.getDeclaredMethod("myUserId");
uid = (int) m.invoke(null);
} catch (Exception e) {
e.printStackTrace();
}

ContentResolver下的uri

content:// USER_ID @media/external/audio/media

即可获取不同用户下的不同数据
安卓adb多用户操作
awesome-adb
Android 多用户

环境变量设置

手动设置:

chenyudeMacBook-Pro:~ chenyu$ open .bash_profile

chenyudeMacBook-Pro:~ chenyu$ source .bash_profile

自动设置:

export PATH=$PATH:/Users/chenyulong01/gradle/gradle-7.3/bin

端口查看

sudo lsof -i :8088 // 查看端口使用情况
sudo kill -9 47862 // 杀死展示的PID

npm install https certificate

1
2
3
4
5
chenyudeMacBook-Pro:Robot chenyu$ npm install
npm ERR! request to https://registry.cnpmjs.org/base-64 failed, reason: Hostname/IP doesn't match certificate's altnames: "Host: registry.cnpmjs.org. is not in the cert's altnames: DNS:r.cnpmjs.org"

npm ERR! A complete log of this run can be found in:
npm ERR! /Users/chenyu/.npm/_logs/2021-08-09T06_53_57_119Z-debug.log

解决方案:关闭https认证:

1
chenyudeMacBook-Pro:Robot chenyu$ npm config set strict-ssl false

nps穿透

安装

$ cd /opt/nps

$ ./nps install -config=/etc/nps/nps.conf

启动

$ sudo nps start

其他命令

停止

$ sudo nps stop

客户端更新

$ sudo nps-update update

修改配置

如果需要更换命令内容需要先卸载./nps uninstall,再重新安装

$ cd /opt/nps

$ ./nps uninstall

成功后再重新安装

$ ./nps install -config=/etc/nps/nps.conf

linux卸载nps,CentOS安装nps

异常相关

Android Studio 不能调试

提示异常:Attention! No symbol directories found - please check your native debug configuration

解决方案:在Android studio, file–>settering—>plugins—-android NDK support插件的选项去掉。重新编译后再debug就可以了。

android studio无法debug解决方法

Android Studio - Connect to 127.0.0.1:8888 [/127.0.0.1] failed: Connection refused (Connection refused)

Could not resolve com.anjuke.android.community:communitymodule:1014-1.0.0.
Could not get resource ‘http://artifactory.58corp.com:8081/artifactory/android-public/com/anjuke/android/community/communitymodule/1014-1.0.0/communitymodule-1014-1.0.0.pom'.
Could not GET ‘http://artifactory.58corp.com:8081/artifactory/android-public/com/anjuke/android/community/communitymodule/1014-1.0.0/communitymodule-1014-1.0.0.pom'.
Connect to 127.0.0.1:8888 [/127.0.0.1] failed: Connection refused (Connection refused)

解决方案:cmd:lsof -i,找到COMMAND java 对应的 PID,然后kill 98087

1
2
3
4
5
6
chenyulong01deMacBook-Pro:~ chenyulong01$ lsof -i
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
java 77690 chenyulong01 211u IPv6 0x426c9f64949f384b 0t0 TCP *:65337 (LISTEN)
chenyulong01deMacBook-Pro:~ chenyulong01$
chenyulong01deMacBook-Pro:~ chenyulong01$ kill 77690
chenyulong01deMacBook-Pro:~ chenyulong01$

使用Xposed去hook方法TestArray(Person[] person)

1
2
3
4
5
6
7
8
9
Class<?> personClass = findClass("com.zq.inputmethodtest.Person",lpparam.classLoader);
findAndHookMethod("com.zq.inputmethodtest.MainActivity", lpparam.classLoader,
"TestArray",java.lang.reflect.Array.newInstance(personClass, 2).getClass(), new XC_MethodHook() {
@Override
protected void afterHookedMethod(MethodHookParam param) throws Throwable {
param.setResult("person数组被修改");
Log.d("InputTest-->after ",""+ param.getResult());
}
});

Execution failed for JetifyTransform

1
2
3
Suggestions:
- If you believe this library doesn't need to be jetified (e.g., if it already supports AndroidX, or if it doesn't use support libraries/AndroidX at all), add android.jetifier.blacklist = {<!-- -->comma-separated list of regular expressions (or simply names) of the libraries that you don't want to be jetified} to the gradle.properties file.
- If you believe this library needs to be jetified (e.g., if it uses old support libraries and breaks your app if it isn't jetified), contact the library's authors to update this library to support AndroidX and use the supported version once it is released.

解决方案:在gradle.properties配置文件中添加,android.jetifier.blacklist = common-27.1.0.jar,bundletool-0.14.0.jar

Duplicate jar entry [a.class])

1
2
Execution failed for task ':58WuxianClient:minifyReleaseWithProguard'.
> java.io.IOException: Can't write [/Users/chenyulong01/AndroidStudioProjects/58/58town/58ClientProject/58WuxianClient/build/intermediates/shrunk_jar/release/minified.jar] (Can't read [/Users/chenyulong01/.gradle/caches/transforms-2/files-2.1/1749dbd4dcd5d376e66539c8b1f84b24/jetified-asm-analysis-7.0.jar(;;;;;;;**.class)] (Duplicate jar entry [a.class]))

解决方案:在gradle task 中,点击执行androidDependencies,打印出所有依赖列表,查找出重复对组,然后去去除依赖即可。

1
2
3
4
5
6
7
8
9
10
11
+--- org.ow2.asm:asm-commons:7.0@jar
+--- org.ow2.asm:asm-util:7.0@jar
+--- org.ow2.asm:asm-analysis:7.0@jar
+--- org.ow2.asm:asm-tree:7.0@jar

implementation ('com.android.tools.build:gradle:4.0.2')
{
exclude group: 'javax.activation'
exclude group: 'org.apache.httpcomponents'
exclude group: 'org.ow2.asm'
}

Duplicate class javax.activation.ActivationDataFlavor found in modules

1
java.lang.RuntimeException: Duplicate class javax.activation.ActivationDataFlavor found in modules javax.activation-1.2.0.jar (com.sun.activation:javax.activation:1.2.0) and javax.activation-api-1.2.0.jar (javax.activation:javax.activation-api:1.2.0)

解决方案:

1
2
3
4
5
6
7
implementation ('com.android.tools.lint:lint-gradle:27.0.2')
{
exclude group: 'com.sun.activation', module: 'javax.activations'
exclude group: 'com.google.code.findbugs'
exclude group: 'javax.inject'
exclude group: 'com.android.tools.external.com-intellij'
}