当前位置:   article > 正文

idea 创建打包 android App_idea 开发安卓apk

idea 开发安卓apk

1、使用 idea 创建 android 工程

2、 配置构建 sdk

3、配置 gradle

a、进入 gradle 官网,选择 install (默认是最新版本)

b、选择包管理安装,手动安装选择下面一个即可

c、安装 sdk 并通过 sdk 安装 gradle

安装 sdk:curl -s "https://get.sdkman.io" | bash

根据安装提示,执行 source 命令使 sdkman 生效

source "/Users/xxxx/.sdkman/bin/sdkman-init.sh"

然后执行 gradle 安装命令

安装成功

4、下载软件 Genymotion,并在IDEA安装一个Genymotion插件与之关联起来

a、下载安装 adb

模拟器下载地址:Genymotion Desktop download - Genymotion Android Emulator

配置自己下载安装的 android sdk 路径

b、安装插件

配置模拟器路径

5、配置完成执行命令打包构建

gradle assembleDebug 打包出现异常如下

  1. Starting a Gradle Daemon (subsequent builds will be faster)
  2. FAILURE: Build failed with an exception.
  3. * What went wrong:
  4. A problem occurred configuring root project 'My Application'.
  5. > Could not resolve all files for configuration ':classpath'.
  6. > Could not resolve com.android.tools.build:gradle:8.2.2.
  7. Required by:
  8. project : > com.android.application:com.android.application.gradle.plugin:8.2.2
  9. > No matching variant of com.android.tools.build:gradle:8.2.2 was found. The consumer was configured to find a library for use during runtime, compatible with Java 8, packaged as a jar, and its dependencies declared externally, as well as attribute 'org.gradle.plugin.api-version' with value '8.6' but:
  10. - Variant 'apiElements' capability com.android.tools.build:gradle:8.2.2 declares a library, packaged as a jar, and its dependencies declared externally:
  11. - Incompatible because this component declares a component for use during compile-time, compatible with Java 11 and the consumer needed a component for use during runtime, compatible with Java 8
  12. - Other compatible attribute:
  13. - Doesn't say anything about org.gradle.plugin.api-version (required '8.6')
  14. - Variant 'javadocElements' capability com.android.tools.build:gradle:8.2.2 declares a component for use during runtime, and its dependencies declared externally:
  15. - Incompatible because this component declares documentation and the consumer needed a library
  16. - Other compatible attributes:
  17. - Doesn't say anything about its target Java version (required compatibility with Java 8)
  18. - Doesn't say anything about its elements (required them packaged as a jar)
  19. - Doesn't say anything about org.gradle.plugin.api-version (required '8.6')
  20. - Variant 'runtimeElements' capability com.android.tools.build:gradle:8.2.2 declares a library for use during runtime, packaged as a jar, and its dependencies declared externally:
  21. - Incompatible because this component declares a component, compatible with Java 11 and the consumer needed a component, compatible with Java 8
  22. - Other compatible attribute:
  23. - Doesn't say anything about org.gradle.plugin.api-version (required '8.6')
  24. - Variant 'sourcesElements' capability com.android.tools.build:gradle:8.2.2 declares a component for use during runtime, and its dependencies declared externally:
  25. - Incompatible because this component declares documentation and the consumer needed a library
  26. - Other compatible attributes:
  27. - Doesn't say anything about its target Java version (required compatibility with Java 8)
  28. - Doesn't say anything about its elements (required them packaged as a jar)
  29. - Doesn't say anything about org.gradle.plugin.api-version (required '8.6')
  30. * Try:
  31. > Review the variant matching algorithm at https://docs.gradle.org/8.6/userguide/variant_attributes.html#sec:abm_algorithm.
  32. > No matching variant errors are explained in more detail at https://docs.gradle.org/8.6/userguide/variant_model.html#sub:variant-no-match.
  33. > Run with --stacktrace option to get the stack trace.
  34. > Run with --info or --debug option to get more log output.
  35. > Run with --scan to get full insights.
  36. > Get more help at https://help.gradle.org.
  37. BUILD FAILED in 22s

根据异常提示:Incompatible because this component declares a component, compatible with Java 11 and the consumer needed a component, compatible with Java 8

发现gradle 使用的是默认的 jdk8 版本,与工程要求的 11 版本不一致

2种解决方式如下:

1、gradle.properties 中 指定 jdk 版本:org.gradle.java.home=/Applications/Android\ Studio.app/Contents/jbr/Contents/Home

2、在命令行中指定

gradle -Dorg.gradle.java.home=/Applications/Android\ Studio.app/Contents/jbr/Contents/Home assembleDebug

解决后再次打包即可完成 !!!

本文内容由网友自发贡献,转载请注明出处:https://www.wpsshop.cn/w/小舞很执着/article/detail/836699
推荐阅读
相关标签
  

闽ICP备14008679号