使用带有支持库的库时,如何正确设置targetSdkVersion为26

问题描述 投票:1回答:2

我试图将目标API提升到26(从22开始),到目前为止还有一些困难。

出于某种原因,我的Gradle继续认为25.3.1仍然是支持库的最新版本。

所以,这是我的库项目的build.gradle:

apply plugin: 'com.android.library'

android {
    compileSdkVersion 26
    buildToolsVersion '26.0.1'
    publishNonDefault true

    defaultConfig {
        targetSdkVersion 26
        minSdkVersion 14
        versionCode 1
        versionName "1.0"
    }
}

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

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    compile 'com.android.support:support-v4:25.3.1'
}

主要项目的相关部分:

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

    defaultConfig {
        targetSdkVersion 26
        minSdkVersion 14
    }
}
dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    compile project(path: ':MyLibrary', configuration: 'debug')
}

似乎无论我做什么,Android Studio都无法识别存储库并提供升级到支持库版本26,但是当我只包含25版时会抱怨。

我刚刚完成了查看与问题甚至远程相关的每个SO问题,而且几乎所有问题都只是将新存储库添加到依赖项中。我添加错误吗?

尝试手动将support-v4库设置为26.0.2 version会导致"failed to resolve" gradle错误。

我仍然缺少什么设置让这对我有用?

android android-support-library android-8.0-oreo
2个回答
0
投票

首先将目标API设置为26.然后同步gradle。同步过程完成后清理Project。


0
投票
apply plugin: 'com.android.application'

android {useLibrary'org.apache.http.legacy'compileSdkVersion 26 buildToolsVersion '26 .0.1'

defaultConfig {
    applicationId "com.common.yourprojectname"
    minSdkVersion 16
    targetSdkVersion 26
    versionCode 1
    versionName "1.0"

    /*jackOptions {
        enabled true
    }*/

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


/* compileOptions {
    sourceCompatibility JavaVersion.VERSION_1_8
    targetCompatibility JavaVersion.VERSION_1_8
}*/
dexOptions {
    javaMaxHeapSize "4g"
}

}

dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
//apt 'com.bluelinelabs:logansquare-compiler:1.3.6'

compile files('libs/android-viewbadger.jar')
//noinspection GradleCompatible
compile 'com.android.support:appcompat-v7:26.1.0'
compile 'com.android.support:design:26.1.0'
compile 'com.android.support:support-v4:26.1.0'
compile 'com.android.support:recyclerview-v7:26.1.0'
compile 'com.android.support:cardview-v7:26.1.0'
compile 'com.android.volley:volley:1.0.0'
compile 'com.jakewharton:butterknife:8.4.0'
compile 'com.google.android.gms:play-services-ads:8.4.0'
compile 'com.github.bumptech.glide:glide:3.7.0'
compile 'com.bluelinelabs:logansquare:1.3.6'
compile 'com.weiwangcn.betterspinner:library-material:1.1.0'
compile 'com.intuit.sdp:sdp-android:1.0.4'
compile 'org.greenrobot:eventbus:3.0.0'
compile 'com.android.support.constraint:constraint-layout:1.0.2'
compile 'me.dm7.barcodescanner:zxing:1.9.8'
compile 'com.github.javiersantos:MaterialStyledDialogs:2.1'
compile 'com.oguzdev:CircularFloatingActionMenu:1.0.2'
compile 'de.hdodenhof:circleimageview:2.1.0'
compile('com.payumoney.sdkui:plug-n-play:1.0.0') {
    transitive = true;
    exclude module: 'payumoney-sdk'
}

compile 'com.payumoney.core:payumoney-sdk:7.0.1'
/*compile('com.crashlytics.sdk.android:crashlytics:2.6.5@aar') {
    transitive = true;
}*/
testCompile 'junit:junit:4.12'
annotationProcessor 'com.jakewharton:butterknife-compiler:8.4.0'
annotationProcessor 'com.bluelinelabs:logansquare-compiler:1.3.6'

}

© www.soinside.com 2019 - 2024. All rights reserved.