9

终端基于gradle的开源项目运行环境配置指引

 3 years ago
source link: https://blog.bihe0832.com/android-as-gradle-config.html
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

因为墙以及不同开发者的环境的原因,经常会出现clone了一个开源项目以后无法运行的情况,因此专门整理了个人的开源项目在引用或者运行时一些通用的注意事项,其实所有开源项目在第一次运行时都可能遇到这些问题。

个人的项目gradle插件的两个版本都有使用:

  • 一般涉及到NDK的,大部分使用实验版的gradle插件
  • 原生项目基本上使用标准版

两个版本的差异可以查看之前写过的两篇文章Gradle Android插件使用的中那些特别注意的点基于Android Studio使用gradle构建包含jni以及so的构建实例,下面不在区分实验板和标准版

含NDK项目

  • 修改项目根目录local.properies中的ndk.dirsdk.dir的环境配置。ndk.dir为NDK工具的本地路径,sdk.dir为SDK工具的本地路径。如下面事例的最后两行

      ## This file is automatically generated by Android Studio.
      # Do not modify this file -- YOUR CHANGES WILL BE ERASED!
      #
      # This file must *NOT* be checked into Version Control Systems,
      # as it contains information specific to your local configuration.
      #
      # Location of the SDK. This is only used by Gradle.
      # For customization when using a Version Control System, please read the
      # header note.
      #Mon Mar 13 16:35:36 CST 2017
      sdk.dir=/Users/zixie/lib/android-sdk
      ndk.dir =/Users/zixie/lib/android-ndk-r10e
  • 修改项目根目录gradle/wrapper/gradle-wrapper.properties中使用的gradle版本的地址,建议不要修改gradle的版本,仅修改引用地址即可。如下面事例的最后一行

      #Tue Apr 19 20:27:20 CST 2016
      distributionBase=GRADLE_USER_HOME
      distributionPath=wrapper/dists
      zipStoreBase=GRADLE_USER_HOME
      zipStorePath=wrapper/dists
      distributionUrl=file\:/Users/zixie/lib/gradle/distribution/gradle-2.10-all.zip
  • 修改项目根目录build.gradle中对于使用的maven库的声明,如下面事例的maven地址

      buildscript {
          repositories {
              maven { url "http://maven.bihe0832.com:8081/nexus/content/repositories/android"}
              jcenter()
          }
          dependencies {
              classpath 'com.android.tools.build:gradle:1.+'
          }
      }
    	
      allprojects {
          repositories {
              maven { url "http://maven.bihe0832.com:8081/nexus/content/repositories/android"}
              jcenter()
          }
      }
  • 如果是标准版本修改项目根目录gradle.properties文件,添加参数:android.useDeprecatedNdk=true,如下面事例的最后一行

      ## Project-wide Gradle settings.
      #
      # For more details on how to configure your build environment visit
      # http://www.gradle.org/docs/current/userguide/build_environment.html
      #
      # Specifies the JVM arguments used for the daemon process.
      # The setting is particularly useful for tweaking memory settings.
      # Default value: -Xmx10248m -XX:MaxPermSize=256m
      # org.gradle.jvmargs=-Xmx2048m -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8
      #
      # When configured, Gradle will run in incubating parallel mode.
      # This option should only be used with decoupled projects. More details, visit
      # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
      # org.gradle.parallel=true
      #Wed Apr 27 10:09:30 CST 2016
      android.useDeprecatedNdk=true

不含NDK项目

  • 修改项目根目录local.properies中的sdk.dir的环境配置。sdk.dir为SDK工具的本地路径。如下面事例的最后两行

      ## This file is automatically generated by Android Studio.
      # Do not modify this file -- YOUR CHANGES WILL BE ERASED!
      #
      # This file must *NOT* be checked into Version Control Systems,
      # as it contains information specific to your local configuration.
      #
      # Location of the SDK. This is only used by Gradle.
      # For customization when using a Version Control System, please read the
      # header note.
      #Mon Mar 13 16:35:36 CST 2017
      sdk.dir=/Users/zixie/lib/android-sdk
  • 修改项目根目录gradle/wrapper/gradle-wrapper.properties中使用的gradle版本的地址,建议不要修改gradle的版本,仅修改引用地址即可。如下面事例的最后一行

      #Tue Apr 19 20:27:20 CST 2016
      distributionBase=GRADLE_USER_HOME
      distributionPath=wrapper/dists
      zipStoreBase=GRADLE_USER_HOME
      zipStorePath=wrapper/dists
      distributionUrl=file\:/Users/zixie/lib/gradle/distribution/gradle-2.10-all.zip
  • 修改项目根目录build.gradle中对于使用的maven库的声明,如下面事例的maven地址

      buildscript {
          repositories {
              maven { url "http://maven.bihe0832.com:8081/nexus/content/repositories/android"}
              jcenter()
          }
          dependencies {
              classpath 'com.android.tools.build:gradle:1.+'
          }
      }
    	
      allprojects {
          repositories {
              maven { url "http://maven.bihe0832.com:8081/nexus/content/repositories/android"}
              jcenter()
          }
      }

当上面的配置都修改OK以后,即可正常运行,可以通过以下两种形式中的任意一种来运行。

  • 使用Android Studio 逐个导入

  • 一般我的项目都会提供构建shell,可以直接在根目录运行build.sh。运行后会在项目根目录的bin目录下生成相关资源或者安装包




About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK