【问题标题】:How to add Java 8+. Build with Maven in android project如何添加 Java 8+。在 android 项目中使用 Maven 构建
【发布时间】:2019-07-03 07:08:58
【问题描述】:

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

其实我在github上看到过一个项目,所以要使用那个项目,我必须添加Prerequisites。

这是我的 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'
}

【问题讨论】:

标签: java android maven


【解决方案1】:

在您的 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

【讨论】:

    【解决方案2】:

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

    【讨论】:

    • 你能解释一下吗?
    • 制作一个普通的pom,添加上面链接的插件,然后放入你需要的依赖。你可以在这里找到它们:mvnrepository.com
    猜你喜欢
    • 2016-03-15
    • 2015-08-13
    • 1970-01-01
    • 2016-01-30
    • 1970-01-01
    • 2016-04-19
    • 2012-09-28
    • 1970-01-01
    • 2015-11-30
    相关资源
    最近更新 更多