android studio 调试问题解决记录

问题1:cache.properties 拒绝访问 

Error:D:\app\.gradle\buildOutputCleanup\cache.properties 拒绝访问

打开cache.properties 文件一看,只有一行gradle.version=4.4,明显不对,

配置成实际的 gradle.version=5.4.1

重新编译就通过了。

问题2:AAPT error

D:\app\build\intermediates\incremental\mergeDebugResources\merged.dir\values\values.xml: AAPT: error: file failed to compile.

D:\app\src\main\res\values\id.xml:4:5-44: AAPT: error: inner element must either be a resource reference or empty.

打开 id.xml ,显示




    12
    34

改成:

问题3:Gradle DSL method not found:‘apply()’

删除了以前安装的C:\program files\android\gradle 5.6.2 目录,目前使用的是5.4.1-all。

由于是以前的代码重新引入,网上看到可能是gradle文件的utf-8格式的原因。

所以将 D:\xxx\app\build.gradle 删除,重新拷贝了一个能用的build.gradle 到目录D:\xxx\app\下。

重新make project 通过。

问题4:merge-state 拒绝访问

D:\app\build\intermediates\incremental\debug-mergeJavaRes\merge-state (拒绝访问。)

解决方法:配置Compile Sdk Version和Build Tools Version版本,满足 AVD 设备Pixel2 API 28的要求。 

apply plugin: 'com.android.application'

android {

    sourceSets {
        main {
            jniLibs.srcDirs = ['libs']
        }
    }

    compileSdkVersion 29
    buildToolsVersion '29.0.2'

    defaultConfig {
        applicationId "com.ilove.sp"
        minSdkVersion 20
        targetSdkVersion 28
        versionCode 168
        versionName "1.6.8"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
        multiDexEnabled true
        javaCompileOptions { annotationProcessorOptions { includeCompileClasspath = true } }
    }
    signingConfigs {
        release {
            keyAlias 'aaa'
            keyPassword '888888'
            storeFile file('keystore.jks')
            storePassword '888888'
        }
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
            debuggable true
            signingConfig signingConfigs.release
        }
        debug {
            signingConfig signingConfigs.release
        }
    }
}

dependencies {
    api fileTree(include: ['*.jar'], dir: 'libs')

    api('com.android.support.test.espresso:espresso-core:2.2.2', {
        exclude group: 'com.android.support', module: 'support-annotations'
    })

    api project(':business')
    api files('libs/simple_crop_image_lib.jar')
    api files('libs/AMap_Location_V3.4.0_20170427.jar')
    api files('libs/Amap_2DMap_V4.2.0_20170209.jar')
    api files('libs/AMap_Search_V5.0.0_20170309.jar')
    api files('libs/pinyin4j-2.5.0.jar')
    api files('libs/xUtils-2.6.14.jar')
    api files('libs/MobCommons-2017.0412.1554.jar')
    api files('libs/MobTools-2017.0412.1554.jar')
    api files('libs/ShareSDK-Core-2.8.3.jar')
    api files('libs/ShareSDK-ShortMessage-2.8.3.jar')
    api files('libs/ShareSDK-Wechat-2.8.3.jar')
    api files('libs/ShareSDK-Wechat-Core-2.8.3.jar')
    api files('libs/ShareSDK-Wechat-Moments-2.8.3.jar')
    api files('libs/alipaySdk-20170725.jar')
    api files('libs/pushservice-5.6.0.30.jar')

    api 'com.android.support:multidex:1.0.1'
    api 'com.android.support.constraint:constraint-layout:1.0.2'
    api 'com.android.support:appcompat-v7:25.3.1'
    api 'com.github.bumptech.glide:glide:3.6.1'
    api 'com.android.support:recyclerview-v7:25.3.1'
    api 'com.android.support:support-v4:25.3.1'
    api 'com.jakewharton:butterknife:7.0.1'
    api 'de.hdodenhof:circleimageview:2.0.0'
    api 'org.xutils:xutils:3.1.15'
    api 'ch.acra:acra:4.6.2'
    api 'com.tencent.mm.opensdk:wechat-sdk-android-with-mta:1.1.6'
    api 'com.android.support:design:25.3.1'
    api 'de.greenrobot:eventbus:2.4.0'

    api 'junit:junit:4.12'

    api 'io.reactivex:rxandroid:1.0.1'
    api 'com.github.promeg:tinypinyin:2.0.1'

}

编译通过,可以run 起来,进入安卓虚拟手机调试器了。

问题 5、签名打包

由于使用的是gradle 3.5.1 ,和以前的build.gradle 打包apk 配置有变化,参见下面的红色部分,

apply plugin: 'com.android.application'

android {

    sourceSets {
        main {
            jniLibs.srcDirs = ['libs']
        }
    }

    compileSdkVersion 29
    buildToolsVersion '29.0.2'

    defaultConfig {
        applicationId "com.ilove.sp"
        minSdkVersion 20
        targetSdkVersion 28
        versionCode 180
        versionName "1.8.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
        multiDexEnabled true
        javaCompileOptions { annotationProcessorOptions { includeCompileClasspath = true } }
    }
    signingConfigs {
        release {
            keyAlias 'aaa'
            keyPassword '888888'
            storeFile file('keystore.jks')
            storePassword '888888'
        }
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
            debuggable true
            signingConfig signingConfigs.release
        }
        debug {
            signingConfig signingConfigs.release
        }
    }

    applicationVariants.all { variant ->
        if (variant.buildType.name != "debug") {
            variant.getPackageApplicationProvider().get().outputDirectory = new File(project.rootDir.absolutePath + "/apk")
        }

        variant.getPackageApplicationProvider().get().outputScope.apkDatas.forEach { apkData ->
            apkData.outputFileName = ((project.name != "app") ? project.name : rootProject.name) + "-" +
                    variant.versionName + "_" +
                    variant.flavorName + "_" +
                    variant.buildType.name + 
                    ".apk"
        }
    }

}

dependencies {
    api fileTree(include: ['*.jar'], dir: 'libs')

    api('com.android.support.test.espresso:espresso-core:2.2.2', {
        exclude group: 'com.android.support', module: 'support-annotations'
    })

    api project(':business')
     //圆形头像
    api files('libs/simple_crop_image_lib.jar')
    api files('libs/AMap_Location_V3.4.0_20170427.jar')
    api files('libs/Amap_2DMap_V4.2.0_20170209.jar')
    api files('libs/AMap_Search_V5.0.0_20170309.jar')
    api files('libs/pinyin4j-2.5.0.jar')
    api files('libs/xUtils-2.6.14.jar')
    api files('libs/MobCommons-2017.0412.1554.jar')
    api files('libs/MobTools-2017.0412.1554.jar')
    api files('libs/ShareSDK-Core-2.8.3.jar')
    api files('libs/ShareSDK-ShortMessage-2.8.3.jar')
    api files('libs/ShareSDK-Wechat-2.8.3.jar')
    api files('libs/ShareSDK-Wechat-Core-2.8.3.jar')
    api files('libs/ShareSDK-Wechat-Moments-2.8.3.jar')
    //    compile files('libs/libammsdk.jar')
    api files('libs/alipaySdk-20170725.jar')
    api files('libs/pushservice-5.6.0.30.jar')

    api 'com.android.support:multidex:1.0.1'
    api 'com.android.support.constraint:constraint-layout:1.0.2'
    api 'com.android.support:appcompat-v7:25.3.1'
    api 'com.github.bumptech.glide:glide:3.6.1'
    api 'com.android.support:recyclerview-v7:25.3.1'
    api 'com.android.support:support-v4:25.3.1'
    api 'com.jakewharton:butterknife:7.0.1'
//    compile 'com.jakewharton:butterknife:8.4.0'

    api 'de.hdodenhof:circleimageview:2.0.0'
    api 'org.xutils:xutils:3.1.15'
    api 'ch.acra:acra:4.6.2'
    api 'com.tencent.mm.opensdk:wechat-sdk-android-with-mta:1.1.6'
    api 'com.android.support:design:25.3.1'
    api 'de.greenrobot:eventbus:2.4.0'

    api 'junit:junit:4.12'

    api 'io.reactivex:rxandroid:1.0.1'
    api 'com.github.promeg:tinypinyin:2.0.1'

}

在 D:\ app\build\outputs\apk\debug目录下看到了打包成功的ilove.apk。

安装到手机上测试,满足设计要求。可以上传到各app 应用市场了。

你可能感兴趣的:(android studio 调试问题解决记录)