Android 优化

性能优化

RecyclerView 滑动优化,滑动过程中禁止加载图片

 recyclerview.addOnScrollListener(new RecyclerView.OnScrollListener(){
public void onScrollStateChanged(@NonNull RecyclerView recyclerView, int newState) {
  if(newState == 0){//无滑动 SCROLL_STATE_IDLE
     adapter.setIsScroll(false);
     adapter.notifyDataSetChanged();    
  }else if(newState ==2){ //滑动
     adapter.setIsScroll(true);
  }
})

Redex

** github地址**:https://github.com/facebook/redex
优点:使用Redex优化减少包体积,加载启动速度。
缺点:如果程序出现问题,定位问题点很难。

macOS

xcode安装好了的可以跳过安装
xcode-select --install

Install dependencies using homebrew:
brew install autoconf automake libtool python3
brew install boost jsoncpp

git clone https://github.com/facebook/redex.git
cd redex

#if you're using gcc, please use gcc-4.9
autoreconf -ivf && ./configure && make -j4
sudo make install

可选操作:
./test/setup.sh
cd test
make check

生成新包:
To use ReDex, first build your app and find the APK for it. Then run:
redex path/to/your.apk -o path/to/output.apk

例如:
redex /Users/.../105.apk -o /Users/.../107.apk

出现如下错误:

Couldn't find zipalign. See README.md to resolve this.
Traceback (most recent call last):
  File "/tmp/redex.ce7j6x/redex.py", line 893, in <module>
    run_redex(args)
  File "/tmp/redex.ce7j6x/redex.py", line 876, in run_redex
    finalize_redex(state)
  File "/tmp/redex.ce7j6x/redex.py", line 788, in finalize_redex
    state.args.keyalias, state.args.keypass, state.args.ignore_zipalign, state.args.page_align_libs)
  File "/tmp/redex.ce7j6x/redex.py", line 344, in create_output_apk
    zipalign(unaligned_apk_path, output_apk_path, ignore_zipalign, page_align)
  File "/tmp/redex.ce7j6x/redex.py", line 298, in zipalign
    raise Exception('Zipalign failed to run')
Exception: Zipalign failed to run

ANDROID_SDK=/Users/../sdk redex /Users/.../105.apk -o /Users/../107.apk。
中间的省略号是文件路径。

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

友情链接更多精彩内容