gradle Android Studio更新后链接引用失败

时间:2018-09-24 21:08:38

标签: android gradle android-studio-3.0

更新Gradle之后,我得到了这个错误(我在更新Gradle的同时还添加了maven {jitpack.io}和geofirestore依赖项):

Android resource linking failed
Output:  C:\Users\Paul\AndroidStudioProjects\How2Ride2\app\build\intermediates\incremental\mergeDebugResources\merged.dir\values-v28\values-v28.xml:7: error: resource android:attr/dialogCornerRadius not found.
C:\Users\Paul\AndroidStudioProjects\How2Ride2\app\build\intermediates\incremental\mergeDebugResources\merged.dir\values-v28\values-v28.xml:11: error: resource android:attr/dialogCornerRadius not found.
C:\Users\Paul\AndroidStudioProjects\How2Ride2\app\build\intermediates\incremental\mergeDebugResources\merged.dir\values\values.xml:1169: error: resource android:attr/fontVariationSettings not found.
C:\Users\Paul\AndroidStudioProjects\How2Ride2\app\build\intermediates\incremental\mergeDebugResources\merged.dir\values\values.xml:1170: error: resource android:attr/ttcIndex not found.
error: failed linking references.

Command: C:\Users\Paul\.gradle\caches\transforms-1\files-1.1\aapt2-3.2.0-4818971-windows.jar\74062dcec80f00402d5904d26f22db6e\aapt2-3.2.0-4818971-windows\aapt2.exe link -I\
        C:\Users\Paul\AppData\Local\Android\Sdk\platforms\android-27\android.jar\
        --manifest\
        C:\Users\Paul\AndroidStudioProjects\How2Ride2\app\build\intermediates\merged_manifests\debug\processDebugManifest\merged\AndroidManifest.xml\
        -o\
        C:\Users\Paul\AndroidStudioProjects\How2Ride2\app\build\intermediates\processed_res\debug\processDebugResources\out\resources-debug.ap_\
        -R\
        @C:\Users\Paul\AndroidStudioProjects\How2Ride2\app\build\intermediates\incremental\processDebugResources\resources-list-for-resources-debug.ap_.txt\
        --auto-add-overlay\
        --java\
        C:\Users\Paul\AndroidStudioProjects\How2Ride2\app\build\generated\not_namespaced_r_class_sources\debug\processDebugResources\r\
        --custom-package\
        com.how2ride.how2ride\
        -0\
        apk\
        -c\
        en,fr\
        --output-text-symbols\
        C:\Users\Paul\AndroidStudioProjects\How2Ride2\app\build\intermediates\symbols\debug\R.txt\
        --no-version-vectors
Daemon:  AAPT2 aapt2-3.2.0-4818971-windows Daemon #0

我该如何解决?

这是我的Project构建包:

buildscript {

    repositories {
        google()
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.2.0'


        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
        classpath 'com.google.gms:google-services:4.0.2'
    }
}

allprojects {
    repositories {
        google()
        jcenter()

        maven { url 'https://jitpack.io' }
    }
}

task clean(type: Delete) {
    delete rootProject.buildDir
}

和我的模块构建gradle:

    apply plugin: 'com.android.application'

android {
    compileSdkVersion 27
    defaultConfig {
        applicationId "com.how2ride.how2ride"
        minSdkVersion 21
        targetSdkVersion 27
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
        resConfigs "en", "fr"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    //noinspection GradleCompatible
    implementation 'com.android.support:appcompat-v7:27.1.1'
    implementation 'com.android.support:support-v4:27.1.1'
    implementation 'com.android.support:design:27.1.1'
    implementation 'com.google.android.gms:play-services-maps:15.0.1'
    implementation "com.google.android.gms:play-services-location:15.0.1"
    implementation 'com.google.firebase:firebase-ads:15.0.1'
    implementation 'com.google.firebase:firebase-core:16.0.3'
    implementation 'com.firebaseui:firebase-ui-auth:4.1.0'
    implementation 'com.google.firebase:firebase-auth:16.0.3'
    implementation 'com.google.firebase:firebase-firestore:17.1.0'
    implementation 'com.github.imperiumlabs:GeoFirestore-Android:v1.1.1'
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'com.android.support.test:runner:1.0.2'
    androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
}

apply plugin: 'com.google.gms.google-services'

我使用的是最新版本的android studio,并且在升级gradle之前,我的项目可以正常运行。

7 个答案:

答案 0 :(得分:44)

将compileSdkVersion更改为:

compileSdkVersion 28

这些属性已在此版本中添加。选中hereherehere

答案 1 :(得分:8)

将gradle版本降级为3.1.4,即classpath'com.android.tools.build:gradle:3.1.4'

答案 2 :(得分:6)

在3.1.4上降级gradle。 检查您的 build.gradle (Modele:App)文件:

convert_model_krs_tfjs.py
-------------------------
import keras
from keras.models import model_from_json 
from keras.optimizers import SGD
import numpy as np
from time import sleep
import tensorflowjs as tfjs

model = model_from_json(open('Face_model_architecture.json').read())
model.load_weights('Face_model_weights.h5')
sgd = SGD(lr=0.1, decay=1e-6, momentum=0.9, nesterov=True)
model.compile(loss='categorical_crossentropy', optimizer=sgd)
model.save("Keras-64x2-10epoch")
tfjs.converters.save_keras_model(model, "face")

My python worked code:
----------------------
detectemotion.py
----------------
from keras.models import model_from_json
from keras.optimizers import SGD
import numpy as np
from time import sleep
model = model_from_json(open('./models/Face_model_architecture.json').read())
#model.load_weights('_model_weights.h5')
model.load_weights('./models/Face_model_weights.h5')
sgd = SGD(lr=0.1, decay=1e-6, momentum=0.9, nesterov=True)
model.compile(loss='categorical_crossentropy', optimizer=sgd)
print(model)
def extract_face_features(gray, detected_face, offset_coefficients):
        (x, y, w, h) = detected_face
        #print x , y, w ,h
        horizontal_offset = np.int(np.floor(offset_coefficients[0] * w))
        vertical_offset = np.int(np.floor(offset_coefficients[1] * h))


        extracted_face = gray[y+vertical_offset:y+h, 
                          x+horizontal_offset:x-horizontal_offset+w]
        #print extracted_face.shape
        new_extracted_face = zoom(extracted_face, (48. / extracted_face.shape[0], 
                                               48. / extracted_face.shape[1]))
        new_extracted_face = new_extracted_face.astype(np.float32)
        new_extracted_face /= float(new_extracted_face.max())
        return new_extracted_face
from scipy.ndimage import zoom
def detect_face(frame):
        cascPath = "./models/haarcascade_frontalface_default.xml"
        faceCascade = cv2.CascadeClassifier(cascPath)
        gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
        detected_faces = faceCascade.detectMultiScale(
                gray,
                scaleFactor=1.1,
                minNeighbors=6,
                minSize=(48, 48),
                flags=cv2.CASCADE_SCALE_IMAGE
            )
        return gray, detected_faces

import cv2
cascPath = "haarcascade_frontalface_default.xml"
faceCascade = cv2.CascadeClassifier(cascPath)

video_capture = cv2.VideoCapture(0)

while True:
    # Capture frame-by-frame
#    sleep(0.8)
    ret, frame = video_capture.read()

    # detect faces
    gray, detected_faces = detect_face(frame)

    face_index = 0

    # predict output
    for face in detected_faces:
        (x, y, w, h) = face
        if w > 100:
            # draw rectangle around face 
            cv2.rectangle(frame, (x, y), (x+w, y+h), (0,255,0), 2)

            # extract features
            extracted_face = extract_face_features(gray, face, (0.075, 0.05)) #(0.075, 0.05)

            # predict smile
            prediction_result = model.predict_classes(extracted_face.reshape(1,48,48,1))

            # draw extracted face in the top right corner
            frame[face_index * 48: (face_index + 1) * 48, -49:-1, :] = cv2.cvtColor(extracted_face * 255, cv2.COLOR_GRAY2RGB)

            # annotate main image with a label
            if prediction_result == 3:
                cv2.putText(frame, "Happy!!",(x,y), cv2.FONT_ITALIC, 2, (255,255,255), 2)
            elif prediction_result == 0:
                cv2.putText(frame, "Angry",(x,y), cv2.FONT_HERSHEY_SIMPLEX, 2, (255,255,255), 2)
        elif prediction_result == 1:
                cv2.putText(frame, "Disgust",(x,y), cv2.FONT_HERSHEY_SIMPLEX, 2, (255,255,255), 2)
        elif prediction_result == 2:
                cv2.putText(frame, "Fear",(x,y), cv2.FONT_HERSHEY_SIMPLEX, 2, (255,255,255), 2)
        elif prediction_result == 4:
                cv2.putText(frame, "Sad",(x,y), cv2.FONT_HERSHEY_SIMPLEX, 2, (255,255,255), 2)
        elif prediction_result == 5:
                cv2.putText(frame, "Surprise",(x,y), cv2.FONT_HERSHEY_SIMPLEX, 2,(255,255,255), 2)
        else :
                cv2.putText(frame, "Neutral",(x,y), cv2.FONT_HERSHEY_SIMPLEX, 2,(255,255,255), 2)


            # increment counter
            face_index += 1


    # Display the resulting frame
    cv2.imshow('Video', frame)

    if cv2.waitKey(1) & 0xFF == ord('q'):
        break

# When everything is done, release the capture
video_capture.release()
cv2.destroyAllWindows()

该项目已建成:)

答案 3 :(得分:4)

检查您的 graddle-wrapper.properties 文件

Sun Jul 08 23:40:54 KST 2018
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-4.4-all.zip

检查gradle版本文件url的最后一行

答案 4 :(得分:3)

在此build.gradle中尝试此代码

 classpath 'com.android.tools.build:gradle:3.1.4'

答案 5 :(得分:2)

将您的类路径设置为当前的构建gradle,并同步您的项目。AndroidStudio 3.2版似乎存在问题。当提示更新gradle时,还更新了classpath值。

答案 6 :(得分:2)

对于我来说,在更新到新的gradle 3.0.1至3.2.0之后,今天遇到了这个问题,我删除了values文件夹中的ids.xml文件(在项目中没有用)对我来说有用