2017-08-24 87 views
29

今天下載了studio 3.0 beta 2.0版本,之後試圖打開一個已有的項目並面臨一些困難,其中大部分我都可以在Google的幫助下解決和堆棧溢出,但這一個我不能。invokedynamic requires --min-sdk-version> = 26

Error:Execution failed for task ':app:transformClassesWithDexBuilderForDebug'. 
> com.android.build.api.transform.TransformException: org.gradle.tooling.BuildException: com.android.dx.cf.code.SimException: invalid opcode ba (invokedynamic requires --min-sdk-version >= 26) 

還張貼我的應用程序gradle這個

apply plugin: 'com.android.application' 
    android { 
    compileSdkVersion 26 
    buildToolsVersion "26.0.1" 

defaultConfig { 
    applicationId "com.intersoft.snappy" 
    minSdkVersion 19 
    targetSdkVersion 22 
    multiDexEnabled true 
    versionCode 1 
    versionName "1.0" 
} 
buildTypeMatching 'dev', 'debug' 
buildTypeMatching 'qa', 'debug' 
buildTypeMatching 'rc', 'release' 
buildTypes { 
    release { 
     minifyEnabled false 
     proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 
    } 
} 
sourceSets { main { assets.srcDirs = ['src/main/assets', 'src/main/assets/'] 
} } 
packagingOptions { 
    exclude 'META-INF/DEPENDENCIES.txt' 
    exclude 'META-INF/LICENSE.txt' 
    exclude 'META-INF/NOTICE.txt' 
    exclude 'META-INF/NOTICE' 
    exclude 'META-INF/LICENSE' 
    exclude 'META-INF/DEPENDENCIES' 
    exclude 'META-INF/notice.txt' 
    exclude 'META-INF/license.txt' 
    exclude 'META-INF/dependencies.txt' 
    exclude 'META-INF/LGPL2.1' 
} 
} 
repositories { 
mavenCentral() 
mavenLocal() 
jcenter() 
maven { url "https://plugins.gradle.org/m2/" } 
maven { url "https://s3.amazonaws.com/repo.commonsware.com" } 
maven { url "https://jitpack.io" } 
maven { url 'https://dl.bintray.com/ashokslsk/CheckableView' } 
maven { url "https://maven.google.com" } 

} 
android { 
useLibrary 'org.apache.http.legacy' 
} 
dependencies { 
implementation fileTree(include: ['*.jar'], dir: 'libs') 
implementation 'com.android.support:appcompat-v7:26.0.1' 
implementation 'com.github.mrengineer13:snackbar:1.2.0' 
implementation 'com.android.support:recyclerview-v7:26.0.1' 
implementation 'com.android.support:cardview-v7:26.0.1' 
implementation 'com.android.support:design:26.0.1' 
implementation 'com.android.support:percent:26.0.1' 
implementation 'dev.dworks.libs:volleyplus:+' 
implementation 'com.google.guava:guava:21.0' 
implementation 'com.facebook.fresco:fresco:1.0.1' 
implementation 'com.github.bumptech.glide:glide:3.7.0' 
implementation 'com.wdullaer:materialdatetimepicker:3.1.1' 
implementation 'com.squareup.picasso:picasso:2.5.2' 
implementation 'com.github.stfalcon:frescoimageviewer:0.4.0' 
implementation 'com.github.piotrek1543:CustomSpinner:0.1' 
implementation 'com.android.support:multidex:1.0.2' 
implementation 'com.github.satyan:sugar:1.4' 
implementation 'com.hedgehog.ratingbar:app:1.1.2' 
implementation project(':sandriosCamera') 
implementation('org.apache.httpcomponents:httpmime:4.2.6') { 
    exclude module: 'httpclient' 
} 
implementation 'com.googlecode.json-simple:json-simple:1.1' 
} 

afterEvaluate { 
tasks.matching { 
    it.name.startsWith('dex') 
}.each { dx -> 
    if (dx.additionalParameters == null) { 
     dx.additionalParameters = ['--multi-dex'] 
    } else { 
     dx.additionalParameters += '--multi-dex' 
    } 
} 
} 
subprojects { 
project.plugins.whenPluginAdded { plugin -> 
    if ("com.android.build.gradle.AppPlugin".equals(plugin.class.name)) { 
     project.android.dexOptions.preDexLibraries = false 
    } else if 
("com.android.build.gradle.LibraryPlugin".equals(plugin.class.name)) { 
     project.android.dexOptions.preDexLibraries = false 
    } 
} 
} 

buildscript { 
repositories { 
    mavenCentral() 
} 

dependencies { 
    classpath 'com.jakewharton.hugo:hugo-plugin:1.2.1' 
} 
} 

apply plugin: 'com.jakewharton.hugo' 

也是我的另一個模塊gradle這個

apply plugin: 'com.android.library' 
apply plugin: 'com.jfrog.bintray' 
apply plugin: 'com.github.dcendents.android-maven' 

buildscript { 
repositories { 
    jcenter() 
    jcenter() 
    maven { url "https://maven.google.com" } 
} 
dependencies { 
    classpath 'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.7' 
    classpath 'com.github.dcendents:android-maven-gradle-plugin:1.4.1' 
} 
} 

group = 'com.sandrios.android' 
version = '1.0.8' 

ext { 
PUBLISH_GROUP_ID = 'com.sandrios.android' 
PUBLISH_ARTIFACT_ID = 'sandriosCamera' 
PUBLISH_VERSION = '1.0.8' 
PUBLISH_CODE = 9 
} 

android { 
compileSdkVersion 26 
buildToolsVersion "26.0.1" 

defaultConfig { 
    minSdkVersion 19 
    targetSdkVersion 25 
    versionCode PUBLISH_CODE 
    versionName PUBLISH_VERSION 
} 

buildTypes { 
    release { 
     minifyEnabled false 
     proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 
    } 
} 
lintOptions { 
    abortOnError false 
} 
} 

task generateSourcesJar(type: Jar) { 
from android.sourceSets.main.java.srcDirs 
classifier 'sources' 
} 

task generateJavadocs(type: Javadoc) { 
failOnError false 
source = android.sourceSets.main.java.srcDirs 
classpath += project.files(android.getBootClasspath() 
     .join(File.pathSeparator)) 
} 

task generateJavadocsJar(type: Jar) { 
from generateJavadocs.destinationDir 
classifier 'javadoc' 
} 

generateJavadocsJar.dependsOn generateJavadocs 

artifacts { 
archives generateSourcesJar 
archives generateJavadocsJar 
} 

install { 
repositories.mavenInstaller { 
    pom.project { 
     name PUBLISH_GROUP_ID 
     description 'Simple integration of universal camera in android for easy image and video capture.' 
     url 'https://github.com/sandrios/sandriosCamera' 
     inceptionYear '2016' 

     packaging 'aar' 
     version PUBLISH_VERSION 

     scm { 
      connection 'https://github.com/sandrios/sandriosCamera.git' 
      url 'https://github.com/sandrios/sandriosCamera' 

     } 
     developers { 
      developer { 
       name 'arpitgandhi9' 
      } 
     } 
    } 
} 
} 

bintray { 
Properties properties = new Properties() 

properties.load(project.rootProject.file('local.properties').newDataInputStream()) 
user = properties.getProperty('bintray.user') 
key = properties.getProperty('bintray.apikey') 
configurations = ['archives'] 
pkg { 
    repo = 'android' 
    name = 'sandriosCamera' 
    userOrg = 'sandriosstudios' 
    desc = 'Android solution to simplify work with different camera apis.' 
    licenses = ['MIT'] 
    labels = ['android', 'camera', 'photo', 'video'] 
    websiteUrl = 'https://github.com/sandrios/sandriosCamera' 
    issueTrackerUrl = 'https://github.com/sandrios/sandriosCamera/issues' 
    vcsUrl = 'https://github.com/sandrios/sandriosCamera.git' 
    version { 
     name = PUBLISH_VERSION 
     vcsTag = PUBLISH_VERSION 
     desc = 'Minor fixes.' 
     released = new Date() 
    } 
} 
} 

repositories { 
jcenter() 
} 

dependencies { 
implementation 'com.android.support:support-v4:26.0.0' 
implementation 'com.android.support:appcompat-v7:26.0.0' 
implementation 'com.android.support:recyclerview-v7:26.0.0' 
implementation 'com.github.bumptech.glide:glide:3.6.1' 
implementation 'com.yalantis:ucrop:2.2.0' 
implementation 'gun0912.ted:tedpermission:1.0.2' 
} 

而且項目水平gradle這個

// Top-level build file where you can add configuration options common to 
all sub-projects/modules. 

buildscript { 
repositories { 
    jcenter() 
} 
dependencies { 
    classpath 'com.android.tools.build:gradle:3.0.0-beta2' 

    // NOTE: Do not place your application dependencies here; they belong 
    // in the individual module build.gradle files 
} 
} 

allprojects { 
repositories { 
    jcenter() 
    maven { 
     url "https://maven.google.com" 
    } 
} 
} 

請幫我擺脫這個錯誤

+0

請發表您的gradle-wrapper.properties文件 –

+0

@IntelliJAmiya僅3.0α和β,因爲我知道 – DeKaNszn

+0

@ShaifaliPundir我沒有張貼gradle-wrapper.properties,因爲我是相當有信心它是與此無關 – Nilabja

回答

7

發現我的回答,對我個人來說它是使用

implementation "com.google.guava:guava:23.0" 

相反的

implementation "com.google.guava:guava:23.0-android" 
+2

恕我直言:在Android應用程序中使用番石榴是不好的解決方案 – DeKaNszn

+0

這是爲什麼?它出什麼問題了? – TheHebrewHammer

+3

太胖的庫。它將強制使用multidex。如果你想使用番石榴一個或兩個類 - 只提取這些類,並把它放到你的應用程序 – DeKaNszn

43

是很重要的組成部分:

android { 
    compileOptions { 
     sourceCompatibility JavaVersion.VERSION_1_8 
     targetCompatibility JavaVersion.VERSION_1_8 
    } 
} 

你也忘了加回購的插件:

buildscript { 
    repositories { 
     jcenter() 
     google() 
    } 
} 
+1

很確定他不能使用Java 1.8,因爲他的min SDK是19.我有同樣的問題。此外,我試圖做到這一點,錯誤仍然存​​在。 – TheHebrewHammer

+1

我使用min SDK 15. Gradle Plugin 2.4+爲代碼運行'desugar',你可以在https://developer.android.com/studio/write/java8-support.html查看'lambda support' – DeKaNszn

+0

@TheHebrewHammer Android插件v3將採用Java 8代碼並基於min SDK版本生成兼容的Dex。它支持Java 8語言結構,但不支持諸如java.time之類的新API。 –

17

我遇到了同樣的錯誤(SimException)。我曾在機器人清潔建築項目3個模塊:

  • 資料(Android庫)
  • 域(普通Java模塊)
  • 演示(應用程序 - 所有Android的東西)

解決方案

導航到File/Project Structure...

確保你的模塊具有相同的源和目標兼容性(在這種情況下爲1.8)

+0

即使kotlin模塊需要在java庫模塊使用1.8時立即設置「sourceCompatibility」和「targetCompatibility」。感謝提示。 –

+0

當我試圖編譯Scala for Android時,我收到了一個類似的錯誤,這也是爲了解決這個問題。 –

1

我遇到了同樣的問題。我最近刪除了我的.gradle緩存文件夾,並重新安裝了Android Studio和SDK。最後當試圖git bisect的問題,它走了。我只能猜測爲什麼發生這種情況,但我懷疑下載舊版本的構建工具和SDK,並用這些較舊的工具構建(並推測是緩存)我們代碼的版本,導致它的構建方式沒有這樣做,導致問題。

這指出了某種錯誤的方式,即較新的(API 26?)構建工具正在構建源代碼,所以如果您看到此問題和其他解決方案無法正常工作,是將您的目標SDK版本降低到25或更低,安裝必要的構建工具,並嘗試編譯您的代碼,然後再恢復到構建工具26或更高版本。

5

我添加了一個庫,compileOptions Java 1.8,在我的主要項目不。 修正了補充道:

compileOptions { 
    sourceCompatibility JavaVersion.VERSION_1_8 
    targetCompatibility JavaVersion.VERSION_1_8 
} 
+0

對我來說同樣的問題,增加它解決了這個問題 –