我在Android Studio中加载小部件时遇到问题

时间:2018-09-26 14:49:25

标签: android xml android-layout android-studio android-recyclerview

我不知道为什么会发生此问题,因此我打开了android studio并没有加载RecyclerView和其他小部件的视图,因为我清理了缓存也使用了Rebuild Project,但是问题仍然存在,不胜感激支持

 <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:app="http://schemas.android.com/apk/res-auto"
        xmlns:tools="http://schemas.android.com/tools"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        app:layout_behavior="@string/appbar_scrolling_view_behavior">

        <android.support.v7.widget.RecyclerView
            android:id="@+id/recycler"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:clipToPadding="false"
            android:scrollbarStyle="outsideOverlay"
            android:scrollbarThumbVertical="@android:color/transparent"
            android:scrollbars="vertical"
            app:layout_behavior="@string/appbar_scrolling_view_behavior"
            tools:listitem="@layout/item_list_specialties_list"
            tools:itemCount="6"
            tools:layoutManager="android.support.v7.widget.LinearLayoutManager"
            tools:spanCount="1" />
    </RelativeLayout>

enter image description here

这是buildgradle

apply plugin: 'com.android.application'
apply plugin: 'io.fabric'

apply from: "$rootProject.rootDir/app/config.gradle"                  //Compile Play Store
//apply from: "$rootProject.rootDir/app/config-share-fabric.gradle"     //Compile Fabric

def keystoreProperties = new Properties()
def keystorePropertiesFile = rootProject.file("keystore.properties")
keystoreProperties.load(new FileInputStream(keystorePropertiesFile))

def serverProperties = new Properties()
def serverPropertiesFile = rootProject.file("server.properties")
serverProperties.load(new FileInputStream(serverPropertiesFile))

def configuration = ext.configuration
def configurationUser = ext.configurationUser
def configurationSpecialist = ext.configurationSpecialist
def configurationSeller = ext.configurationSeller

android {
    compileSdkVersion configuration.compileSdk
    buildToolsVersion configuration.buildTools

    defaultConfig {
        applicationId configuration.applicationId
        minSdkVersion configuration.minimumSdk
        targetSdkVersion configuration.targetSdk
        vectorDrawables.useSupportLibrary = true
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
        testHandleProfiling true
        testFunctionalTest true

        multiDexEnabled true

        resConfigs("es", "en")

        manifestPlaceholders = [
                projectName : configuration.projectName,
                fabricApiKey: "17fdb5821b7ac5a50e3250fb679a180d9ab54889"
        ]

        resValue("string", "project_name", "\"${configuration.projectName}\"")

        // Used by Room, to test migrations
        javaCompileOptions {
            annotationProcessorOptions {
                arguments = ["room.schemaLocation":
                                     "$projectDir/schemas".toString()]
            }
        }
    }

    //See https://stackoverflow.com/a/36931232
    /*sourceSets {
        main {
            res.srcDirs = [
                    'src/main/res',
                    'src/main/res/drawable',
                    'src/main/res/drawable/splash',
                    'src/main/res/drawable/selectors'
            ]
        }
    }*/

    signingConfigs {
        debug {
            keyAlias keystoreProperties['keyAliasDebug']
            keyPassword keystoreProperties['keyPasswordDebug']
            storeFile file(keystoreProperties['storeFileDebug'])
            storePassword keystoreProperties['storePasswordDebug']
        }
        configReleaseUser {
            keyAlias keystoreProperties['keyAliasUser']
            keyPassword keystoreProperties['keyPasswordUser']
            storeFile file(keystoreProperties['storeFileUser'])
            storePassword keystoreProperties['storePasswordUser']
        }
        configReleaseSpecialist {
            keyAlias keystoreProperties['keyAliasSpecialist']
            keyPassword keystoreProperties['keyPasswordSpecialist']
            storeFile file(keystoreProperties['storeFileSpecialist'])
            storePassword keystoreProperties['storePasswordSpecialist']
        }
        configReleaseSeller {
            keyAlias keystoreProperties['keyAliasSeller']
            keyPassword keystoreProperties['keyPasswordSeller']
            storeFile file(keystoreProperties['storeFileSeller'])
            storePassword keystoreProperties['storePasswordSeller']
        }
    }

    flavorDimensions "app", "server"
    productFlavors {
        user {
            dimension "app"

            applicationId configurationUser.applicationId
            versionCode configurationUser.versionCode
            versionName "${configurationUser.versionMajor}.${configurationUser.versionMinor}" +
                    ".${configurationUser.versionPath}-${configurationUser.versionClasifier}"

            proguardFile 'user-proguard-rules.pro'
            testApplicationId "pe.com.linkup.android.test.user"
        }
        specialist {
            dimension "app"

            applicationId configurationSpecialist.applicationId
            versionCode configurationSpecialist.versionCode
            versionName "${configurationSpecialist.versionMajor}.${configurationSpecialist.versionMinor}" +
                    ".${configurationSpecialist.versionPath}-${configurationSpecialist.versionClasifier}"

            proguardFile 'specialist-proguard-rules.pro'
            testApplicationId "pe.com.linkup.android.test.specialist"
        }
        seller {
            dimension "app"

            applicationId configurationSeller.applicationId
            versionCode configurationSeller.versionCode
            versionName "${configurationSeller.versionMajor}.${configurationSeller.versionMinor}" +
                    ".${configurationSeller.versionPath}-${configurationSeller.versionClasifier}"

            proguardFile 'seller-proguard-rules.pro'
            testApplicationId "pe.com.linkup.android.test.seller"
        }

        //Desarrollo Local
        local {
            dimension "server"

            applicationIdSuffix ".local"
        }
        //Desployment Fabric
        dev {
            dimension "server"

            applicationIdSuffix ".dev"
        }
        //Desployment PlayStore - Testing
        staging {
            dimension "server"

            //applicationIdSuffix ".staging"
        }
        //Desployment PlayStore - Production
        production {
            dimension "server"
        }
    }

    // Configura específicamente cada Flavor
    productFlavors.all { flavor ->
        switch (flavor.name) {
            case "user":
                flavor.manifestPlaceholders.put("appName", configurationUser.appName)

                flavor.resValue("string", "app_name", "\"${configurationUser.appName}\"")
                break
            case "specialist":
                flavor.manifestPlaceholders.put("appName", configurationSpecialist.appName)

                flavor.resValue("string", "app_name", "\"${configurationSpecialist.appName}\"")
                break
            case "seller":
                flavor.manifestPlaceholders.put("appName", configurationSeller.appName)

                flavor.resValue("string", "app_name", "\"${configurationSeller.appName}\"")
                break
            case "local":
                flavor.buildConfigField("String", "BASE_URL", "\"${serverProperties['baseUrlLocal']}\"")
                flavor.buildConfigField("String", "CLIENT_ID", "\"${serverProperties['clientIdLocal']}\"")
                flavor.buildConfigField("String", "CLIENT_SECRET", "\"${serverProperties['clientSecretLocal']}\"")
                flavor.buildConfigField("String", "GRANT_TYPE", "\"${serverProperties['grantTypeLocal']}\"")
                break
            case "dev":
                flavor.buildConfigField("String", "BASE_URL", "\"${serverProperties['baseUrlDev']}\"")
                flavor.buildConfigField("String", "CLIENT_ID", "\"${serverProperties['clientIdDev']}\"")
                flavor.buildConfigField("String", "CLIENT_SECRET", "\"${serverProperties['clientSecretDev']}\"")
                flavor.buildConfigField("String", "GRANT_TYPE", "\"${serverProperties['grantTypeDev']}\"")
                break
            case "staging":
                flavor.buildConfigField("String", "BASE_URL", "\"${serverProperties['baseUrlStaging']}\"")
                flavor.buildConfigField("String", "CLIENT_ID", "\"${serverProperties['clientIdStaging']}\"")
                flavor.buildConfigField("String", "CLIENT_SECRET", "\"${serverProperties['clientSecretStaging']}\"")
                flavor.buildConfigField("String", "GRANT_TYPE", "\"${serverProperties['grantTypeStaging']}\"")
                break
            case "production":
                flavor.buildConfigField("String", "BASE_URL", "\"${serverProperties['baseUrlProduction']}\"")
                flavor.buildConfigField("String", "CLIENT_ID", "\"${serverProperties['clientIdProduction']}\"")
                flavor.buildConfigField("String", "CLIENT_SECRET", "\"${serverProperties['clientSecretProduction']}\"")
                flavor.buildConfigField("String", "GRANT_TYPE", "\"${serverProperties['grantTypeProduction']}\"")
                break
            default:
                break
        }
    }

    // Configura las variantes merged. Ejm: applicationId ya viene unido con el applicationIdSuffix
    applicationVariants.all { variant ->
        def name = variant.name
        if (name.contains("Local")) {
            def filesAuthorityValue = variant.applicationId + ".fileProvider"

            variant.mergedFlavor.manifestPlaceholders.put("filesAuthority", filesAuthorityValue)

            variant.buildConfigField("String", "FILES_AUTHORITY", "\"${filesAuthorityValue}\"")
        } else if (name.contains("Dev")) {
            def filesAuthorityValue = variant.applicationId + ".fileProvider"

            variant.mergedFlavor.manifestPlaceholders.put("filesAuthority", filesAuthorityValue)

            variant.buildConfigField("String", "FILES_AUTHORITY", "\"${filesAuthorityValue}\"")

        } else if (name.contains("Staging")) {
            def filesAuthorityValue = variant.applicationId + ".fileProvider"

            variant.mergedFlavor.manifestPlaceholders.put("filesAuthority", filesAuthorityValue)

            variant.buildConfigField("String", "FILES_AUTHORITY", "\"${filesAuthorityValue}\"")
        } else if (name.contains("Production")) {
            def filesAuthorityValue = variant.applicationId + ".fileProvider"

            variant.mergedFlavor.manifestPlaceholders.put("filesAuthority", filesAuthorityValue)

            variant.buildConfigField("String", "FILES_AUTHORITY", "\"${filesAuthorityValue}\"")
        }
    }

    buildTypes {
        debug {
            //applicationIdSuffix ".debug"

            minifyEnabled false
            debuggable true
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'

            productFlavors.user.signingConfig signingConfigs.debug
            productFlavors.specialist.signingConfig signingConfigs.debug
            productFlavors.seller.signingConfig signingConfigs.debug

            buildConfigField "boolean", "LOG", "true"

            // disable crashlytics
            buildConfigField "boolean", "ENABLE_CRASHLYTICS", "false"
            ext.enableCrashlytics = false
        }
        relebug {
            //applicationIdSuffix ".relebug"

            minifyEnabled false
            debuggable true
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'

            buildConfigField "boolean", "LOG", "true"

            // disable crashlytics
            buildConfigField "boolean", "ENABLE_CRASHLYTICS", "false"
            ext.enableCrashlytics = false

            matchingFallbacks = ['release']
        }
        release {
            zipAlignEnabled true
            minifyEnabled true
            shrinkResources true
            debuggable false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'

            productFlavors.user.signingConfig signingConfigs.configReleaseUser
            productFlavors.specialist.signingConfig signingConfigs.configReleaseSpecialist
            productFlavors.seller.signingConfig signingConfigs.configReleaseSeller

            buildConfigField "boolean", "LOG", "false"

            // enable crashlytics
            buildConfigField "boolean", "ENABLE_CRASHLYTICS", "true"
            ext.enableCrashlytics = true
        }
    }

    // Ignora algunas variantes de compilación para su visualización en la BuildVariant
    variantFilter { variant ->
        def app = variant.getFlavors().get(0).name
        def server = variant.flavors.get(1).name
        def isRelease = variant.buildType.name.contains('release')
        def isRelebug = variant.buildType.name.contains('relebug')
        def isDebug = variant.buildType.name.contains('debug')

        if (server.contains('local')) {
            variant.setIgnore(false)
        } else if (server.contains('dev')) {
            variant.setIgnore(false)
        } else if (server.contains('staging')) {
            variant.setIgnore(false)
        } else if (server.contains('production')) {
            variant.setIgnore(true) //Temporal
        }
    }

    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }

    packagingOptions {
        exclude 'META-INF/LICENSE'
        exclude 'META-INF/DEPENDENCIES'
        exclude 'META-INF/LICENSE-FIREBASE.txt'
        exclude 'META-INF/NOTICE'
    }

    lintOptions {
        abortOnError false
        lintConfig file("../lint.xml")
    }
    dexOptions {
        jumboMode true
        //incremental true
    }

    testOptions {
        reportDir "$rootDir/test-reports"
        resultsDir "$rootDir/test-results"
        unitTests {
            returnDefaultValues = true
            all {
                jvmArgs '-XX:MaxPermSize=256m'
                if (it.name == 'testDebugUnitTest') {
                    systemProperty 'debug', 'true'
                }
            }
        }
    }

    //Renombrar Apk de salida
    applicationVariants.all { variant ->
        variant.outputs.all { output ->
            def projectName = "linkup"
            def formattedDate = new Date().format('yyyyMMdd', TimeZone.getTimeZone("UTC"))
            def apkName = "${projectName}-${variant.flavorName}-${variant.versionName}-${variant.versionCode}-${formattedDate}-${variant.buildType.name}" + ".apk"
            def apkDirectory = "${output.outputFile.parent}/apk/${variant.flavorName}/${variant.buildType.name}"
            //outputFileName = new File(apkDirectory, apkName)
            outputFileName = apkName
        }
    }

    crashlytics {
        enableNdk true
        androidNdkOut 'src/main/obj'
        androidNdkLibsOut 'src/main/libs'
    }
}

repositories {
    jcenter()
    google()
    mavenCentral()
    maven { url "https://jitpack.io" }
    maven { url 'https://maven.fabric.io/public' }
}

apply from: "$rootProject.rootDir/app/library.gradle"

def library = ext.library
def libraryTest = ext.libraryTest

dependencies {
    implementation fileTree(include: ['*.jar'], dir: 'libs')
    implementation library.support_appcompat
    implementation library.support_recyclerview
    implementation library.support_v4
    implementation library.support_v13
    implementation library.support_design
    implementation library.support_cardview
    implementation library.support_customtabs
    implementation library.support_annotations
    implementation library.support_vector_drawable
    implementation library.support_constraint
    implementation library.support_multidex

    implementation library.firebase_core
    implementation library.firebase_auth
    implementation library.firebase_database
    implementation library.firebase_storage
    implementation library.firebase_messaging
    implementation library.firebase_config
    implementation library.firebase_invites

    implementation library.exoplayer_core
    implementation library.exoplayer_ui
    implementation library.exoplayer_dash

    implementation library.butterknife
    annotationProcessor library.butterknife_compiler
    implementation library.retrofit2
    implementation library.retrofit2_converter_gson
    implementation library.logging_interceptor
    implementation library.glide
    implementation library.joda_time
    implementation library.shortcut_badger
    implementation library.smiley_rating

    //Room
    implementation library.room
    annotationProcessor library.room_compiler
    implementation library.room_assets

    //GMS
    implementation library.play_services_location
    implementation library.play_services_maps

    // Crashlytics
    implementation(library.crashlytics) {
        transitive = true
    }
    // Crashlytics NDK
    implementation(library.crashlytics_ndk) {
        transitive = true
    }
    implementation library.spinner_date_picker
    //Testing
    testImplementation libraryTest.junit
    testImplementation libraryTest.mockito_core
    testImplementation libraryTest.robolectric
    testImplementation libraryTest.robolectric_shadows
    //UI testing
    // Espresso dependenciesVersions
    androidTestImplementation(libraryTest.expresso_core, {
        exclude group: 'com.android.support', module: 'support-annotations'
    })
}

configurations.all {
    resolutionStrategy.force library.support_annotations
    resolutionStrategy.force 'com.google.code.findbugs:jsr305:3.0.2'
}

//TODO: Pendiente -> https://howards543.ddns.net/gradle-script-with-multi-flavor-resource-management/
task("copyGoogleServicesJson", type: Copy) {
    println 'copyGoogleServicesJson'
    from('$rootProject.rootDir/app/services/dev/google-services.json')
    into("$rootProject.rootDir/app")
    include('*.json')
}

//apply from: "$rootProject.rootDir/setup/artifacts.gradle"
apply plugin: 'com.google.gms.google-services'

仅基于依赖项,这些依赖项已正确添加且代码未移动,我的buildgradle以这种方式对其进行了结构化,其中我使用library.gradle按版本调用了这些库,这是实现的特定代码RecyclerView。

    ext.versions = [
            supportLib        : '28.0.0'
]

    def version = ext.versions
    ext.library = [    
            support_recyclerview    : 'com.android.support:recyclerview-v7:' + version.supportLib
]

1 个答案:

答案 0 :(得分:0)

为此FragmentRecyclerViewActivityFragment主机一起使用。