如何添加Java 8+。在Android项目中使用Maven进行构建

时间:2019-07-03 07:08:58

标签: java android maven

我必须添加Java 8+。在我的Android项目中使用Maven进行构建,怎么做?

实际上,我在github上看到了一个项目,因此,要使用该项目,我必须添加前提条件。

这是我的 build.gradle 文件。

apply plugin: 'com.android.application'

android {
    compileSdkVersion 26
    defaultConfig {
        applicationId "com.vincent.filepickersample"
        minSdkVersion 14
        targetSdkVersion 26
        versionCode 1
        versionName "1.0"
        multiDexEnabled true
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }
    packagingOptions {
        exclude 'META-INF/DEPENDENCIES'
        exclude 'META-INF/NOTICE'
        exclude 'META-INF/NOTICE.txt'
        exclude 'META-INF/LICENSE'
        exclude 'META-INF/LICENSE.txt'
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}
android {
    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }
}

这些是依赖项

dependencies {
    //implementation 'org.apache.poi:poi:4.0.0'
    //implementation 'org.apache.poi:poi-ooxml:4.0.0'
    androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
        exclude group: 'com.android.support', module: 'support-annotations'
    })
    compile 'com.android.support:appcompat-v7:26.1.0'
    testCompile 'junit:junit:4.12'
    compile project(':filepicker')
    //implementation files('libs/poi-3.12-android-a.jar')
    //implementation files('libs/poi-ooxml-schemas-3.12-20150511-a.jar')
    implementation 'com.android.support:multidex:1.0.3'
    implementation 'org.dhatim:fastexcel-reader:0.10.2'
}

2 个答案:

答案 0 :(得分:0)

您必须制作一个pom.xml文件并正常使用,您只需要使用Android Maven Plugin即可在调用mvn install时将其编译为apk。

答案 1 :(得分:0)

在您的 pom.xml 文件中添加正确的编译器插件配置和必需的插件:

<project>
  <packaging>apk</packaging><!-- or apklib --> 
  <properties>
    <java.version>1.8</java.version>
    <maven.compiler.source>${java.version}</maven.compiler.source>
    <maven.compiler.target>${java.version}</maven.compiler.target>
  </properties>
  <!-- skipped other part of POM file -->
  <dependencies>
    <!-- here your compile or test scoped dependencies... -->
  </dependencies>
  <build>
    <plugins>
      <plugin>
        <groupId>com.simpligility.maven.plugins</groupId>
        <artifactId>android-maven-plugin</artifactId>
        <version>4.3.0</version> <!-- use latest release -->
        <extensions>true</extensions>
      </plugin>
    </plugins>
  </build>
</project>

用法:

mvn install

mvn android:help

mvn android:run
mvn android:apk
mvn android:deploy

了解更多here