升级到Android Studio3.0遇到的问题

前些天,google正式发布了Android Studio3.0。看这个版本号,这次是个大更新。升级后发现编译确实有很大的提升,还有最新的错误调试工具,总之,这次的更新google还是很有诚意的。

下载

Andriod Studio3.0下载

遇到的问题

1.flavorDimensions
  • 错误日志
Error:All flavors must now belong to a named flavor dimension. Learn more at https://d.android.com/r/tools/flavorDimensions-missing-error-message.html

原因:gradle3.0需要使用flavorDimensions做多版本打包,修改如下:

android {
    //...
    defaultConfig {
        //...
        flavorDimensions "dimen"
    }
}

然后在productFlavors中做相应的修改

productFlavors {
    productA { dimension "dimen" } 
    productB { dimension "dimen" }
}

配置多个flavorDimensions

android {
    //...
    defaultConfig {
        //...
        flavorDimensions "dimenA","dimenB"
    }
}
productFlavors {
    productA { dimension "dimenA" } 
    productB { dimension "dimenB" }
    productC { dimension "dimenA" }
}

2.apk命名
  • 错误日志
Cannot set the value of read-only property 'outputFile' for ApkVariantOutputImpl_Decorated{apkData=Main{type=MAIN, fullName=busDebug, filters=[]}} of type com.android.build.gradle.internal.api.ApkVariantOutputImpl. Open File

之前的代码:

applicationVariants.all { variant ->
        variant.outputs.each { output ->
            def outputFile = output.outputFile
            if (outputFile != null && outputFile.name.endsWith('.apk')) {
                def fileName = "XXX-${defaultConfig.versionCode}-${defaultConfig.versionName}-${releaseTime()}-${productFlavors.name[0]}"
                if (variant.buildType.name == 'release') {
                    fileName += '.apk'
                } else if (variant.buildType.name == 'debug') {
                    fileName += '_debug.apk'
                } else {
                    fileName += '_other.apk'
                }
                output.outputFile = new File(outputFile.parent, fileName)
            }
        }
    }

gradle3.0 each替换为all,output.outputFile替换为outputFileName,不需要new File了,修改后的代码:

applicationVariants.all { variant ->
        variant.outputs.all {
            def fileName = "XXX-${defaultConfig.versionCode}-${defaultConfig.versionName}-${releaseTime()}-${productFlavors.name[0]}"
            if (variant.buildType.name == 'release') {
                fileName += '.apk'
            } else if (variant.buildType.name == 'debug') {
                fileName += '_debug.apk'
            } else {
                fileName += '_other.apk'
            }
            outputFileName = fileName
        }
    }

需要注意的是,使用Build->Generate Signed APK…的时候,生成的apk包会放在一个以渠道名命名的文件夹下


3.Annotation processors must be explicitly declared now.Please add them to the annotationProcessor configuration.
  • 错误日志
Error:Execution failed for task ':app:javaPreCompilePreProductDebug'.
> Annotation processors must be explicitly declared now.  The following dependencies on the compile classpath are found to contain annotation processor.  Please add them to the annotationProcessor configuration.
    - butterknife-7.0.1.jar (butterknife-7.0.1.jar)
  Alternatively, set android.defaultConfig.javaCompileOptions.annotationProcessorOptions.includeCompileClasspath = true to continue with previous behavior.  Note that this option is deprecated and will be removed in the future.
  See https://developer.android.com/r/tools/annotation-processor-error-message.html for more details.
  • 修复方案
android {
    //...
    defaultConfig {
        //...
        javaCompileOptions {
            annotationProcessorOptions {
                includeCompileClasspath true
            }
        }
    }
}

4.Aapt2Exception
  • 错误日志
Error:(113, 5) error: style attribute '@android:attr/windowEnterAnimation' not found.
Error:(113, 5) error: style attribute '@android:attr/windowExitAnimation' not found.
...
Error:java.util.concurrent.ExecutionException: java.util.concurrent.ExecutionException: com.android.tools.aapt2.Aapt2Exception: AAPT2 error: check logs for details
Error:java.util.concurrent.ExecutionException: com.android.tools.aapt2.Aapt2Exception: AAPT2 error: check logs for details
Error:com.android.tools.aapt2.Aapt2Exception: AAPT2 error: check logs for details
Error:Execution failed for task ':app:processPreProductDebugResources'.
> Failed to execute aapt
  • 解决方案 在gradle.properties中添加如下代码,禁用aapt2编译
android.enableAapt2=false

5.其他

新版本gradle不需要配置buildToolsVersion
dependencies 引入包的时候是这样的

dependencies {
    implementation fileTree(include: ['*.jar'], dir: 'libs')
    androidTestImplementation ...
    implementation project ...
    implementation files ...
    implementation ...
    testImplementation 'junit:junit:4.12'
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
### 回答1: Android Studio 3.0是一款非常流行的集成开发环境,可以帮助开发者进行Android应用程序的开发。而对于想要使用中文界面的用户来说,可以通过安装汉化包来实现。 汉化包是一种翻译补丁,可以将Android Studio的界面、菜单、对话框等内容翻译为中文,让用户更加方便地理解和使用该软件。 安装Android Studio 3.0的汉化包有以下几个步骤: 1. 首先,我们需要下载合适版本的汉化包。可以在一些Android开发社区中搜索到最新的汉化包下载链接。 2. 下载完成后,打开Android Studio 3.0的安装目录。一般情况下,目录在C盘的Program Files下的Android Studio。 3. 在Android Studio的安装目录中,找到plugins文件夹,并将下载的汉化包文件复制到该文件夹下。 4. 重新启动Android Studio。此时,Android Studio会自动加载汉化包,并将界面翻译为中文。 需要注意的是,由于Android Studio的版本更新频繁,不同版本可能会有不同的汉化包文件。因此,在下载汉化包之前,要确认汉化包与当前使用的Android Studio版本相匹配。 总之,安装Android Studio 3.0的汉化包非常简单,只需要将汉化包文件复制到相应的目录下,然后重新启动Android Studio即可。这样,用户就可以使用中文界面进行开发工作了。 ### 回答2: Android Studio 3.0 是一款由 Google 开发的集成开发环境,用于开发 Android 应用程序。它提供了丰富的功能和工具,方便开发者进行应用程序的设计、编码、调试和测试。 Android Studio 3.0 支持英文和其他一些主要语言的界面显示,但并不直接支持中文。然而,有一些志愿者和团队为了方便中文用户,独立开发了汉化包,以将 Android Studio 3.0 界面显示为中文。 汉化包通常提供了对 Android Studio 所有界面元素的本地化翻译,包括菜单、对话框、工具栏和按钮等。安装汉化包后,用户将能够在 Android Studio 中看到中文界面,提高了理解和使用的便捷性。 要使用汉化包,首先需要下载适用于 Android Studio 3.0 版本的汉化包安装文件。在安装之前,需要确保已安装了 Android Studio 3.0。安装汉化包时,可以选择在安装程序中的设置选项中进行相关设置。 安装后,启动 Android Studio 3.0,界面将显示为中文。用户可以在中文界面下进行应用程序的开发、编程和调试,所有的选项和功能都将以中文显示。 需要注意的是,汉化包由第三方开发者提供,并非由 Android Studio 官方团队开发和维护。因此,在使用汉化包时,可能会出现一些未翻译或翻译不准确的情况。 总而言之,Android Studio 3.0 汉化包是为了方便中文用户而开发的,可以将 Android Studio 3.0 的界面翻译成中文,提高了使用的便捷性。虽然汉化包不是官方提供的,但对于不懂英文或习惯使用中文的开发者来说,它是一个很实用的辅助工具。 ### 回答3: Android Studio 3.0 汉化包是一种增加Android Studio界面汉化的工具。Android Studio是一款用于开发Android应用程序的集成开发环境(IDE),它提供了丰富的功能和工具来提高开发效率。然而,原版的Android Studio界面是英文的,对于一些不熟悉英文的开发者来说可能存在一定的障碍。 汉化包的作用就是将Android Studio界面中的英文语言转化为中文,以方便使用者更好地理解和操作。它可以将工作区、菜单、对话框、错误提示等界面元素都转化为中文显示,从而帮助开发者更轻松地使用这个开发工具。 安装汉化包相对简单,一般需要下载适用于相应版本的汉化包文件,然后将其导入到Android Studio中即可。安装完毕后,用户就能够看到Android Studio的界面已经变为中文。同时,汉化包还能够自动翻译代码注释和部分代码提示,提升开发效率。 需要注意的是,汉化包只是将界面元素转化为中文,并不影响Android Studio的功能和特性。开发者依然可以使用原版的功能和工具进行应用程序开发。此外,由于Android Studio版本的更新较快,汉化包可能会有一定的延迟来适应最新版本的界面改动。 总之,Android Studio 3.0汉化包可以提供中文界面,方便不熟悉英文的开发者使用这个强大的开发工具,提高开发效率。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值