美文网首页
Gradle个人见解

Gradle个人见解

作者: 王怀智 | 来源:发表于2018-10-17 15:47 被阅读17次

    AS -Terminal

    如果在输入台中报错: 'adb' /'gradle' 不是内部或外部命令,也不是可运行的程序
    或批处理文件。

    1. 首先找到adb.exe以及gradle的安装路径。

      • adb-> D:\Android\SDK\platform-tools

      • gradle->C:\gradle-4.4-all\gradle-4.4\bin

    2. 然后打开计算机的环境变量设置

      • 在path中添加adb的路径变量

      • 新建GRADLE_HOME,然后输入gradle路径变量

    3. 测试是否成功

      • 在cmd命令中输入adb->Enter->出现adb的版本号以及他的安装路径则表示成功

      • 在cmd命令中输入gradle ->Enter->Welcome to Gradle 4.4则表示成功

      • 或者输入gradle -v 则会显示当前的JVM版本和Gradle版本


    1. gradle命令介绍

      • 当运行gradle命令时,它会在当前目录下寻找build.gradle文件为构建脚本。** build.gradle其实是一个构建配置脚本 **
      task hello{
          doLast{
              println 'Hello Gradle!'
          }
      }
      

      然后在该目录下执行 gradle -q hello

      -q 控制gradle的日志级别,可以保证只输出我们需要的内容。

      • 执行脚本
      ->gradle -q hello
      Hello Gradle!
      
      • Gradle Java构建
      apply plugin: 'java'
      
      可以运行gradle tasks列出任务列表,可以方便查看     java插件给我们提供了那些任务。
      
      apply plugin: 'com.android.application'
      
      运行gradle tasks后
      Android tasks
      

    AS-ProjectTasks

    Android tasks
    -------------
    
    androidDependencies - Displays the Android dependencies of the project.显示项目的依赖情况
    signingReport - Displays the signing info for each variant.显示每个变体的签名信息
    sourceSets - Prints out all the source sets defined in this project.打印项目中定义的所有源集
    
    Build tasks
    -----------
    assemble - Assembles all variants of all applications and secondary packages.汇编所有应用程序和辅助包的所有变体
    assembleAndroidTest - Assembles all the Test applications.组装所有的测试应用程序。
    assembleDebug - Assembles all Debug builds. 组装所有调试构建
    assembleRelease - Assembles all Release builds.组装所有的正式构建
    build - Assembles and tests this project.组装和测试这个项目
    buildDependents - Assembles and tests this project and all projects that depend on it.组装和测试这个项目以及所有依赖于它的项目。
    buildNeeded - Assembles and tests this project and all projects it depends on.组装和测试这个项目以及它所依赖的所有项目。
    clean - Deletes the build directory.删除这个build文件
    cleanBuildCache - Deletes the build cache directory.删除build缓存文件
    compileDebugAndroidTestSources
    compileDebugSources
    compileDebugUnitTestSources
    compileReleaseSources
    compileReleaseUnitTestSources
    mockableAndroidJar - Creates a version of android.jar that's suitable for unit tests.创建一个android版本,适用于测试
    
    Help tasks
    ----------
    buildEnvironment(构建环境) - Displays all buildscript dependencies declared in project ':app'.显示项目':app'中声明的所有构建脚本依赖项。
    components - Displays the components produced by project ':app'. [incubating]显示app制作的组件
    dependencies - Displays all dependencies declared in project ':app'.显示项目':app'中声明的所有依赖项。
    dependencyInsight - Displays the insight into a specific dependency in project ':app'.显示对项目':app'中特定依赖项的洞察。
    dependentComponents - Displays the dependent components of components in project ':app'. 在项目“:app”中显示组件的依赖组件[incubating]
    help - Displays a help message.
    model - Displays the configuration model of project ':app'. [incubating]显示项目app的配置
    projects - Displays the sub-projects of project ':app'.显示项目
    properties - Displays the properties of project ':app'.显示属性
    tasks - Displays the tasks runnable from project ':app'.可以运行的tasks
    
    Install tasks
    -------------
    installDebug - Installs the Debug build.
    installDebugAndroidTest - Installs the android (on device) tests for the Debug build.
    installRelease - Installs the Release build.
    uninstallAll - Uninstall all applications.
    uninstallDebug - Uninstalls the Debug build.
    uninstallDebugAndroidTest - Uninstalls the android (on device) tests for the Debug build.
    uninstallRelease - Uninstalls the Release build.
    
    Verification tasks 验证
    ------------------
    check - Runs all checks.
    connectedAndroidTest - Installs and runs instrumentation tests for all flavors on connected devices.
    connectedCheck - Runs all device checks on currently connected devices.在当前连接的设备上运行所有设备检查
    connectedDebugAndroidTest - Installs and runs the tests for debug on connected devices.
    deviceAndroidTest - Installs and runs instrumentation tests using all Device Providers.
    deviceCheck - Runs all device checks using Device Providers and Test Servers.使用设备提供程序和测试服务器运行所有设备检查
    lint - Runs lint on all variants.在所有变体上运行lint。
    lintDebug - Runs lint on the Debug build.
    lintRelease - Runs lint on the Release build.
    lintVitalRelease - Runs lint on just the fatal issues in the release build.
    test - Run unit tests for all variants.
    testDebugUnitTest - Run unit tests for the debug build.
    testReleaseUnitTest - Run unit tests for the release build.
    

    AS-Gradle番外篇

    1.当执行gradle sourceSets之后...

    build.gradle name: android.sourceSets.androidTest
    Java sources : [app\src\androidTest\java]
    Manifest file : app\src\androidTest\AndroidManifest.xml
    Android resources : [app\src\androidTest\res]
    Assets : [app\src\androidTest\assets]
    AIDL sources : [app\src\androidTest\aidl]
    RenderScript sources :    [app\src\androidTest\rs]
    JNI sources : [app\src\androidTest\jni]
    JNI libraries : [app\src\androidTest\jniLibs]
    Java-style resources : [app\src\androidTest\resources]
    
    1. 当执行完gradle signingReport...

       Variant(变体):debug /release
       Config: debug /release
       Store(存储):..\jksfile\debug.jks
       Alias(别名):whzdebug
       MD5 : AA:1F:8D:7C:A5:09:6D:E4:86:5F:4D:FA:9B:D9:13:CE
       SHA1(**可以查看,正式跟debug还是有区别的**):BF:A7:91:E7:55:A2:D2:86:E6:25:B0:39:7C:60:B8:EA:2D:E8:34:25
       Valid until(有效期):2043年10月9日 星期五
      
    2. 当执行完gradle build...

       Ran lint on variant debug: 17 issues found(17个问题被发现)
       Ran lint on variant release: 17 issues found
       Wrote HTML report to     file:///D:/AndroidStudioProjects/DevelopmentTest/app/build/reports/lint-results.html(打开这个网址可以在线查看信息)
       Wrote XML report to file:///D:/AndroidStudioProjects/DevelopmentTest/app/build/reports/lint-results.xml
      
    3. 当执行完gradle clean 将删除build文件夹下所有内容

    4. 执行gradle cleanBuildCache 删除build文件夹下的缓存

    5. 执行gradle assembleDebug/assembleRelease完之后...

       编译apk,适用于多渠道打包时
       生成文件:
       app/build/outputs/apk/xx/debug+release
       apk文件显示为app-xiaomi-debug.apk
      

    相关文章

      网友评论

          本文标题:Gradle个人见解

          本文链接:https://www.haomeiwen.com/subject/sddrzftx.html