首页 文章 精选 留言 我的

精选列表

搜索[应用程序生命周期管理],共10000篇文章
优秀的个人博客,低调大师

【Andrioid】在Gradle编译时生成一个不同的版本号,动态设置应用程序标题,应用程序图标,更换常数

写项目的时候常常会遇到下面的情况: 1.须要生成測试版本号和正式版本号的apk 2.測试版本号和正式版本号的URL是不一样的 3.測试版本号和正式版本号的包名须要不一致,这样才干安装到同一部手机上面。 4.不同apk须要应用名不同,图标不同,某些常量不同.... 假设你有以上的需求。看这篇文章就对了 When developing an app, you usually have many slightly different versions of this app. The most common example is probably the backend you want to use:productionorstaging. 当我们做开发的时候。常常会须要生成多个版本号的app。 最常见的就是測试版和正式版。 You usually define the base URLs with the other constants of the app. Switching from one environment to the other is done by (un)commenting the right lines: 我们经常须要在应用中定义一些常量,当应用正式公布的时候,经常是凝视掉測试用的部分,放开正式的部分,就像以下一样: public static String BASE_URL = "http://staging.tamere.be" //public static String BASE_URL = "http://production.tamere.be" The process is manual, boring and error prone but hey, changing one line is not that bad, is it? Then you add more and more features that depends on the environment. You maybe want a different icon and then different input validation rules and then ... That's where your build tool can help. Let's see how we can automate the process of generating different APKs for different environment with Gradle. 上面的步骤是烦躁。无味的,改动一个地方还好。代码写多了以后正过来整过去就egg_pain了,这个时候我们Gragle就闪亮登场了 Build variants Gradle has the concepts ofBuild TypesandBuild Flavors. When combining the two, you get aBuild Variant. There two default build types:releaseanddebug. We won't change them in our example but we will create two new flavors:productionandstaging. Gradle默认有release和debug两个版本号。 我们这里添加了production和staging.两两组合就是以下4个版本号了。 As a result, we'll have four different variants: ProductionDebug ProductionRelease StagingDebug StagingRelease Sample project 演示样例项目 The project is pretty simple but shows how you can define for each build variant: an app name an icon constants (in our case aBASE_URLvariable) You can download the project onGithub. Here are two screenshots of the generated apps. Nothing really fancy: 演示样例项目非常easy。在不同的版本号中我们须要改动项目名称。项目图标,一些常量:url...,项目能够从Github下载,效果图例如以下: build.gradle file buildscript { repositories { mavenCentral() } dependencies { classpath 'com.android.tools.build:gradle:0.5.+' } } apply plugin: 'android' repositories { mavenCentral() } android { compileSdkVersion 18 buildToolsVersion "18.0.1" defaultConfig { minSdkVersion 15 targetSdkVersion 18 } productFlavors { production { packageName "be.tamere.gradlebuildtypesexample" } staging { packageName "be.tamere.gradlebuildtypesexample.staging" } } } dependencies { compile 'com.android.support:appcompat-v7:18.0.0' } The definition of the flavors is super simple, all the magic will happen in their folders. 改动非常easy:核心配置是productFlavors,同一时候须要注意production和staging。它们须要与后面的文件夹结构名字一致 File structure 改动后的文件结构 In thesrcfolder, we've created two directories whose names must match the flavors. We will define all the flavor-specific values. Only specific values are necessary. 改动也比較简单,在src以下(main同级的文件夹)新建和上面productFlavors中配置production和staging同样的文件夹,分别放入相应的Constants.java。这两个文件夹的属性和功能与系统默认创建的main是一样的。 总结一下就是: 1.production和staging两个文件夹,相应着各存放一份Constants.java 2.对于应用图标和应用名字信息配置在res文件夹以下的。这个地方针对staging又一次配置了一份ic_launcher.png和string.xml。production没配置的话就是用默认main以下的res。 这个比較easy理解哈。 The staging version defines new icons while both flavors defines aConstants.java. The app name is defined in thestring.xmlfiles. ├── main │ ├── AndroidManifest.xml │ ├── ic_launcher-web.png │ ├── java │ │ └── be │ │ └── tamere │ │ └── gradlebuildtypesexample │ │ └── MainActivity.java │ └── res │ ├── drawable-hdpi │ │ └── ic_launcher.png │ ├── drawable-mdpi │ │ └── ic_launcher.png │ ├── drawable-xhdpi │ │ └── ic_launcher.png │ ├── drawable-xxhdpi │ │ └── ic_launcher.png │ ├── layout │ │ └── activity_main.xml │ ├── menu │ │ └── main.xml │ ├── values │ │ ├── dimens.xml │ │ ├── strings.xml │ │ └── styles.xml │ ├── values-v11 │ │ └── styles.xml │ └── values-v14 │ └── styles.xml ├── production │ └── java │ └── be │ └── tamere │ └── gradlebuildtypesexample │ └── Constants.java └── staging ├── java │ └── be │ └── tamere │ └── gradlebuildtypesexample │ └── Constants.java └── res ├── drawable-hdpi │ └── ic_launcher.png ├── drawable-mdpi │ └── ic_launcher.png ├── drawable-xhdpi │ └── ic_launcher.png ├── drawable-xxhdpi │ └── ic_launcher.png └── values └── string.xml Android Studio You can switch between the two flavors in theBuild variantstab of the IDE. Android Studio has some trouble identifying the resources for a non-active flavors. We are using theproductionflavor, Studio does not understand that thestagingfolder contains source code. Don't worry, it's normal, it will catch up when you switch to the staging variant. Launch the app with the different flavors to see the result. The app drawer shows the two icons: References http://tools.android.com/tech-docs/new-build-system/user-guide#TOC-Product-flavors Xav's answer on thisStack overflow topicis particularly helpful. 原文地址: http://tulipemoutarde.be/2013/10/06/gradle-build-variants-for-your-android-project.html 本文转自mfrbuaa博客园博客,原文链接:http://www.cnblogs.com/mfrbuaa/p/4734552.html,如需转载请自行联系原作者

优秀的个人博客,低调大师

Spring Boot 应用程序启动流程分析

SpringBoot 有两个关键元素: @SpringBootApplication SpringApplication 以及 run() 方法 SpringApplication 这个类应该算是 Spring Boot 框架的“创新”产物了,原始的 Spring 中并没有这个类,SpringApplication 中封装了一套 Spring 应用的启动流程,然而这对用户完全透明,因此我们上手 Spring Boot 时感觉很简洁、轻量。 一般来说默认的 SpringApplication 执行流程已经可以满足大部分需求,但是若用户想干预这个过程,则可以通过 SpringApplication 在流程某些地方开启扩展点来完成对流程的扩展,典型的扩展方案那就是使用 set 方法。 比如,把我们天天司空见惯的 Spring Boot 应用的启动类来拆解一下写出来就是这样: @SpringBootApplication public class CodeSheepApplication { public static void main( String[] args ) { //SpringApplication.run( CodeSheepApplication.class args ); SpringApplication app = new SpringApplication( CodeSheepApplication.class ); app.setXXX( ... ); // 用户自定的扩展在此 !!! app.run( args ); } } 这样一拆解后我们发现,我们也需要先构造 SpringApplication 类对象,然后调用该对象的 run() 方法。那么接下来就讲讲 SpringApplication 的构造过程 以及其 run() 方法的流程,搞清楚了这个,那么也就搞清楚了SpringBoot应用是如何运行起来的! SpringApplication 实例的初始化 我们对照代码来看: 四个关键的步骤已标注在图中,分别解释如下: ① 推断应用的类型:创建的是 REACTIVE应用、SERVLET应用、NONE 三种中的某一种 ② 使用 SpringFactoriesLoader查找并加载 classpath下 META-INF/spring.factories文件中所有可用的 ApplicationContextInitializer ③ 使用 SpringFactoriesLoader查找并加载 classpath下 META-INF/spring.factories文件中的所有可用的 ApplicationListener ④ 推断并设置 main方法的定义类 SpringApplication 的run()方法探秘 先看看代码长啥样子: 各个主要步骤我已经标注在上图之中了,除此之外,我也按照自己的理解画了一个流程图如下所示,可以对照数字标示看一下: 我们将各步骤总结精炼如下: 1、通过 SpringFactoriesLoader 加载 META-INF/spring.factories 文件,获取并创建 SpringApplicationRunListener 对象 2、然后由 SpringApplicationRunListener 来发出 starting 消息 3、创建参数,并配置当前 SpringBoot 应用将要使用的 Environment 4、完成之后,依然由 SpringApplicationRunListener 来发出 environmentPrepared 消息 5、创建 ApplicationContext 6、初始化 ApplicationContext,并设置 Environment,加载相关配置等 7、由 SpringApplicationRunListener 来发出 contextPrepared 消息,告知SpringBoot 应用使用的 ApplicationContext 已准备OK 8、将各种 beans 装载入 ApplicationContext,继续由 SpringApplicationRunListener 来发出 contextLoaded 消息,告知 SpringBoot 应用使用的 ApplicationContext 已装填OK 9、refresh ApplicationContext,完成IoC容器可用的最后一步 10、由 SpringApplicationRunListener 来发出 started 消息 11、完成最终的程序的启动 12、由 SpringApplicationRunListener 来发出 running 消息,告知程序已运行起来了 至此,全流程结束! 声明:本文转载自蛙课网官方网站 想获取更多资讯、更多视频、面试题答案,还有各种资源+源码+工具 就关注“蛙课网校”公众号吧! 还有不定时福利分享活动等你来参加哦

优秀的个人博客,低调大师

简单的Cloud Toolkit教程,助你秒部署应用程序

1.什么是Cloud Toolkit Cloud Toolkit 是开发者本地 IDE 中的一款插件,可以帮助开发者更高效地开发、测试、诊断并部署应用。通过这个插件,可以==将本地应用一键部署到任意服务器==,甚至部署到云端上(阿里云的ECS、EDAS、Kubernetes 和 小程序云 等);并且还内置了 Arthas 诊断、Dubbo工具、Terminal 终端、文件上传和 MySQL 执行器等工具。 2.使用Cloud Toolkit前部署应用的方式 1.编写应用代码 2.打包应用 3.登录服务器 4.将应用包上传到服务器 5.启动应用 或者使应用在后台运行 6.访问应用 3.使用Cloud Toolkit后部署应用的方式 1.安装Cloud Toolkit插件(这里以IDEA为例) 确保 IntelliJ 、PyCharm、PhpStorm等在 2018.1 或更高版本,本文以 IntelliJ 为例 第 1 步:打开 Intellij 的 Settings ( Windows下 ) 或 Preferences( Mac下 )窗口 第 2 步:进入 Plugins 选项,搜索“Alibaba Cloud Toolkit”,并安装即可,如下图: 插件安装成功后,重启 Intellij,您可以在工具栏看到 Alibaba Cloud Toolkit 的图标。 第3步:填写邀请码 4QEFVD 2.在Cloud Toolkit中配置服务器信息 3.配置并上传,部署成功 方式一(带打包的过程,适合使用maven的项目): 打开部署到主机的配置面板 方式二(只上传文件,需要自己手动先打包,适合没有使用maven的项目): 4.访问接口即可 4.以前的部署方式和使用Cloud Toolkit部署的区别 当应用更新代码需要重新部署时,以前的部署方式需要重新执行收下部署步骤: 打包 使用ssh工具登录服务器 将打好包的应用上传到服务器 在服务器上手动或者使用脚本重启应用 而使用Cloud Toolkit只需要以下步骤 打开Cloud Toolkit部署面板,点击运行即可 Cloud Toolkit官网链接:点击进入官网https://www.aliyun.com/product/cloudtoolkit

资源下载

更多资源
Mario

Mario

马里奥是站在游戏界顶峰的超人气多面角色。马里奥靠吃蘑菇成长,特征是大鼻子、头戴帽子、身穿背带裤,还留着胡子。与他的双胞胎兄弟路易基一起,长年担任任天堂的招牌角色。

腾讯云软件源

腾讯云软件源

为解决软件依赖安装时官方源访问速度慢的问题,腾讯云为一些软件搭建了缓存服务。您可以通过使用腾讯云软件源站来提升依赖包的安装速度。为了方便用户自由搭建服务架构,目前腾讯云软件源站支持公网访问和内网访问。

Rocky Linux

Rocky Linux

Rocky Linux(中文名:洛基)是由Gregory Kurtzer于2020年12月发起的企业级Linux发行版,作为CentOS稳定版停止维护后与RHEL(Red Hat Enterprise Linux)完全兼容的开源替代方案,由社区拥有并管理,支持x86_64、aarch64等架构。其通过重新编译RHEL源代码提供长期稳定性,采用模块化包装和SELinux安全架构,默认包含GNOME桌面环境及XFS文件系统,支持十年生命周期更新。

Sublime Text

Sublime Text

Sublime Text具有漂亮的用户界面和强大的功能,例如代码缩略图,Python的插件,代码段等。还可自定义键绑定,菜单和工具栏。Sublime Text 的主要功能包括:拼写检查,书签,完整的 Python API , Goto 功能,即时项目切换,多选择,多窗口等等。Sublime Text 是一个跨平台的编辑器,同时支持Windows、Linux、Mac OS X等操作系统。

用户登录
用户注册