안드로이드 xml 레이아웃이 안보이는 문제 (Gradle 빌드 문제)

조회수 12542회

https://mplatform.seoul.go.kr/w/contest/award/2016/wnpz/selectPageListWinner.do

안드로이드 할줄 몰라서 저 오픈소스를 열어서 공부하려고 했는데요, 실행은 되지만 레이아웃 미리보기가 제대로 안떴습니다. 그래서 그걸 해결하기 위해 구글링하다가 오히려 더 큰 에러가 떠서 결국 질문드리게 되었습니다.


1) 오픈소스를 열었더니 레이아웃 미리보기가 안보였습니다.

  • 레이아웃에 떴던 에러 내용: Render problem Failed to load AppCompat ActionBar with unknown error

이미지


2) 그래서 그 에러메시지를 구글링해보니 스택오버플로우 글이 떴고, 그걸 통해 Gradle가 잘못되었다는 사실은 알았지만 거기에 나와 있는 gradle 코드와 제 gradle 코드가 달라서 적용을 시킬 수가 없었습니다. (답변 내용을 복사해서 붙여넣기 해봤지만 소용없음)

이미지


3) 제 Gradle 코드에 빨간 줄이 그여져 있었고, 해당 에러코드로 구글링을 했습니다. ( compile 'com.android.support:appcompat-v7:23.4.0' )

  • 에러 내용: All com.android.support libraries must use the exact same version specification (mixing versions can lead to runtime crashes). Found versions 23.4.0, 23.0.0. Examples include com.android.support:animated-vector-drawable:23.4.0 and com.android.support:mediarouter-v7:23.0.0

이미지

저 빨간줄 뜨는 부분의 코드는 다음과 같습니다. build.gradle (Module: app)

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

android {
    compileSdkVersion 23
    buildToolsVersion '26.0.2'

    defaultConfig {
        applicationId "com.runfive.hangangrunner"
        minSdkVersion 19
        targetSdkVersion 23
        versionCode 1
        versionName "1.0"
        multiDexEnabled true
    }

    dexOptions {
        jumboMode true
        javaMaxHeapSize "2g"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}
repositories {
    mavenCentral()
}

dependencies {
    compile fileTree(include: ['*.jar'], dir: 'libs')
    testCompile 'junit:junit:4.12'
    compile 'com.android.support:appcompat-v7:23.4.0'
    compile 'com.android.support:support-v4:23.4.0'
    compile 'com.android.support:design:23.4.0'
    //compile 'com.naver.maps.open:naver-map-api:2.1.2@aar'구글맵으로 변경함
    compile project(':decoviewlib')
    compile project(':calendarlib')
    compile 'com.google.android.gms:play-services:9.0.2'
    compile 'com.google.android.gms:play-services:7.5.+'
    //compile 'com.google.android.gms:play-services-maps:9.4.0'
    //compile 'com.google.android.gms:play-services:9.4.0'
    compile 'com.google.maps.android:android-maps-utils:0.4'
    compile 'com.squareup.okhttp:okhttp:2.7.2'
    compile 'com.google.code.gson:gson:2.6.2'
    // dailyfragment에서 씀

    // 페이스북 연동
    compile 'com.facebook.android:facebook-android-sdk:4.6.0'

    // 네이버로그인 연동
    compile files('libs/3rdparty_login_library_android_4.1.4.jar')

    // 카드뷰
    compile 'com.android.support:recyclerview-v7:23.4.0'
    compile 'com.android.support:cardview-v7:23.4.0'

    // 폰트
    compile 'com.tsengvn:Typekit:1.0.0'

    // 하위버전 지원
    compile 'com.android.support:multidex:1.0.0'
}

일단 저 빨간줄 뜨는 지점부터 검색을 해봤거든요... 근데 답변내용을 복사해서 붙여넣기 해봐도 에러가 해결이 안되더군요

https://stackoverflow.com/questions/39188699/failed-to-resolve-com-android-supportappcompat-v723-4-0


그래서 아래의 에러 코드를 구글링해봤습니다.

  • 에러 내용: All com.android.support libraries must use the exact same version specification (mixing versions can lead to runtime crashes). Found versions 23.4.0, 23.0.0. Examples include com.android.support:animated-vector-drawable:23.4.0 and com.android.support:mediarouter-v7:23.0.0

구글링해보니 티스토리 블로그가 나오더군요

블로그 내용에 의하면 "안드로이드 스튜디오 3.1.0 이상 버전에서는 기존 프로젝트에서 이런 빌드 에러가 나타나니 아래의 코드를 추가하라"고 했습니다.


http://dwfox.tistory.com/73

이미지

그래서 저는 블로그에서 시킨대로 저 3줄을 코드에 추가해줬습니다.

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

buildscript {
    repositories {
        jcenter()
        google()
    }
   dependencies {
       classpath 'com.android.tools.build:gradle:3.0.1'
       classpath 'com.android.tools.build:gradle:1.3.0-beta1'
       classpath 'com.google.gms:google-services:1.3.0-beta1'

       compile 'com.android.support:appcompat-v7:25.3.0' //Google Component
       compile 'com.android.support:customtabs:25.3.0'
       compile 'com.android.support:mediarouter-v7:25.3.0'

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

allprojects {
    repositories {
        jcenter()
        google()
    }
}

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

그러자 이번에는 새로운 에러가 떴습니다.

  • 에러 내용: Error:(13, 0) Could not find method compile() for arguments [com.android.support:appcompat-v7:25.3.0] on object of type org.gradle.api.internal.artifacts.dsl.dependencies.DefaultDependencyHandler.

Please install the Android Support Repository from the Android SDK Manager.


이미지

문제를 해결하기 위해 구글링 해서 답변내용을 붙여넣기 하면 또 새로운 에러가 뜨고...

이걸 무한루프처럼 반복하고 있습니다. 어떻게 해결해야 할까요?

1 답변

  • Ah...이거 Gradle은 직접 맞는 버전 확인하시고 선택하셔야 해요...

    저도 겪어봤는데... sdk 매니저 가셔서 sdk Tools 확인해보시면 됩니다 거기에서 sdk 플렛폼 확인하시고 나와있는거 에러난쪽 (버전)에 넣으심 됩니다

    • (•́ ✖ •̀)
      알 수 없는 사용자

답변을 하려면 로그인이 필요합니다.

프로그래머스 커뮤니티는 개발자들을 위한 Q&A 서비스입니다. 로그인해야 답변을 작성하실 수 있습니다.

(ಠ_ಠ)
(ಠ‿ಠ)