查看以下常见问题列表,点击具体的问题即可查看相应解答。
在编译文件时,如果没有网络,很有可能造成编译失败。通过以下步骤,确认编译环境的网络已连接。
如果程序编译失败,可通过以下步骤进行排错与解决。
//引用 debug 包group:artifact:version:raw@jar
bundle "com.app.xxxxx.xxxx:test-build:1.0-SNAPSHOT:raw@jar"
//引用 release 包group:artifact:version@jar
bundle "com.app.xxxxx.xxxx:test-build:1.0-SNAPSHOT@jar"
manifest "com.app.xxxxx.xxxx:test-build:1.0-SNAPSHOT:AndroidManifest@xml"
// 执行命令前,确认未定义 productflavor 属性。否则,命令会运行失败。
// 以下命令将执行记录导出至 log.txt 文件中。
gradle buildDebug --info --debug -Plog=true > log.txt
Caused by: org.gradle.internal.resolve.ArtifactNotFoundException: Could not find nebulacore-build-AndroidManifest.xml (com.alipay.android.phone.wallet:nebulacore-build:1.6.0.171211174825).
Searched in the following locations:
http://mvn.cloud.alipay.com/nexus/content/repositories/releases/com/alipay/android/phone/wallet/nebulacore-build/1.6.0.171211174825/nebulacore-build-1.6.0.171211174825-AndroidManifest.xml
at org.gradle.internal.resolve.result.DefaultBuildableArtifactResolveResult.notFound(DefaultBuildableArtifactResolveResult.java:38)
at org.gradle.api.internal.artifacts.ivyservice.ivyresolve.CachingModuleComponentRepository$LocateInCacheRepositoryAccess.resolveArtifactFromCache(CachingModuleComponentRepository.java:260)
说明:您可以在
build.gradle
文件中查看登录时需要提供的账户名和密码。
gradle
缓存。
gradle clean --refresh-dependencies
说明:删除 Gradle 缓存的方法如下。
- 在 MacOS、Linux、Unix 等系统中,运行以下命令:
cd ~
cd .gradle
cd caches
rm -rf modules-2
- 在 Windows 系统中,默认情况下,路径定位到
C:\Users\\{用户名}\\.gradle\caches
,删除modules-2
文件夹。
如果编译过程卡顿(等待超过 20 分钟),您可以通过以下步骤提高编译效率。
apply plugin: 'maven'
buildscript {
repositories {
mavenLocal()
// 开始先加载 Maven 镜像
maven{ url 'http://maven.aliyun.com/nexus/content/groups/public/'}
maven {
credentials {
username "请使用已知用户"
password "请使用已知密码"
}
url "http://mvn.cloud.alipay.com/nexus/content/repositories/releases/"
}
}
dependencies {
classpath 'com.android.tools.build:gradle:2.1.3'
classpath 'com.alipay.android:android-gradle-plugin:2.1.3.3.3'
classpath 'com.neenbedankt.gradle.plugins:android-apt:1.8'
}
}
allprojects {
repositories {
flatDir {
dirs 'libs'
}
mavenLocal()
maven {
credentials {
username "xxxxxxxxx"
password "xxxxxxx"
}
url "http://mvn.cloud.alipay.com/nexus/content/repositories/releases/"
}
maven{ url 'http://maven.aliyun.com/nexus/content/groups/public/'}
}
}
一般都是配置文件(conf 文件)的问题,需要对字段进行检查。检查 13 个字段是否有缺少;和公有云下载过来的文件进行对比,确认字段名是否正确。
开发过程中需要调试代码,本文介绍两种调试方式。
使用场景:
希望调试应用启动时的最初代码,比如在 application init 时初始化代码。
操作步骤:
执行命令 adb shell am start -W -S -D 应用包名/应用第一个启动的页面类名
。例如,mPaaS Demo 的包名是 com.mpaas.demo
,应用第一个启动的页面类名是com.alipay.mobile.quinox.LauncherActivity
,那么可以使用命令行 adb shell am start -W -S -D com.mpaas.demo/com.alipay.mobile.quinox.LauncherActivity
以调试模式启动应用。第一个启动的类名如下图所示。
执行命令之后,手机会弹出如下对话框。
对希望调试的代码行设置断点,然后附着到应用所在进程即可,如图。
使用场景:
在触发某个事件之后进行调试,比如点击某个按钮或者跳转某个页面才需要调试。
操作步骤:
在应用运行后,点击附着进程()按钮,或者在执行上述命令后,再点击附着按钮开始调试。
接入 mPaaS Inside 的时候,我们已经提供了 MultiDex,因此您可以把官方提供的 MultiDex 从 implementation 中删除。
dependencies{
implementation 'com.android.support:multidex:1.0.3' //删除此行
}
同时,建议您在 gradle 中的 android
这个模块下,把 multiDexEnabled true
加上。
android {
defaultConfig {
multiDexEnabled true
}
}
如果您使用了 mPaaS Inside,同时不接入热修复,并且您需要 MultiDex 支持的话,您依旧要在Application
中调用MultiDex.install(this)
。
public class App extends Application() {
public void attachBaseContext(Context context) {
super.attachBaseContext(context);
MultiDex.install(this);
}
}
QuinoxlessApplication
,您不需要在代码中显式调用。MultiDex 是为了解决 Android 5.0 以下 Dex 方法的数量或者类的数量超过 65535 这个问题的方案。
在当前应用功能膨胀的情况下,我们需要对 Dex 做一些规划。
由于 mPaaS 接入方式是基于 bundle。在打包的时候,bundle 会尝试和用户的 Dex 做一次合并,但 mPaaS 会优先保证用户的首个 Dex 的顺序。
在这种情况下,为了接入 mPaaS,请您尽量避免在 Application 中添加过多的逻辑,使得第一个 dex 尽可能的小。您可以使用 --main-dex-list
参数指定您在第一个 Dex 中的类。
如果您的 apk 中第一个 Dex 类过多导致 mPaaS 必要的几个 bundle 无法合并的话,可能在 Android 5.0 以下的运行时环境中造成无法启动框架(ClassNotFound 或者 ClassNotDef 等问题)。
Portal 和 Bundle 不建议自行介入 MultiDex,除非您是单 portal 工程,需要使用multiDexEnabled true
。如果您的 Bundle 过大,目前只能使用拆分 bundle 的方式进行,不要在 bundle 中开启 multidex 支持。
打开 Gradle 插件的设置界面,点击 Clean Cache 按钮,即可删除 Gradle 插件的所有缓存数据。
目前 Google 官方提供的 Android Gradle Plugin 是 3.5.x 版本。
mPaaS 也提供了 3.5.x 版本的插件作为适配,可支持 Google Android Gradle Plugin 3.5.3 和 Gradle 6.2 的 API。
dependencies {
classpath 'com.alipay.android:android-gradle-plugin:3.5.14'
}
apply plugin:'com.android.application'
,如果您是 portal 工程,仅需要使用 apply plugin:'com.alipay.portal'
。apply plugin:'com.android.application'
, 仅需要使用 apply plugin:'com.alipay.bundle'
。apply plugin:'com.android.library'
。android.buildOnlyTargetAbi=false
。由于我们的无线保镖组件暂不支持 V2 签名,如果您需要使用 Android Studio 调试并安装您的 APK,那么您需要禁用 V2 签名;如果您使用命令行进行构建,且您的 minSdkVersion 大于等于 24,则您也需要禁用 V2 签名。禁用 V2 签名的方式如下:
v2SigningEnabled false
由于华为10 系统 URI 的实现和标准 Android 存在部分差异,因此,在华为 10 上可能存在无法打开摄像机的问题。您需要执行以下操作以解决这个问题。
您可以复用您现有的 FileProvider,也可以新建一个 FileProvider。
import android.support.v4.content.FileProvider;
public class NebulaDemoFileProvider extends FileProvider {
}
<?xml version="1.0" encoding="utf-8"?>
<paths xmlns:android="http://schemas.android.com/apk/res/android">
<external-path name="external" path="."/>
</paths>
<provider
android:name="com.mpaas.demo.nebula.NebulaDemoFileProvider"
android:authorities="com.mpaas.demo.nebula.provider"
android:exported="false"
android:grantUriPermissions="true">
<meta-data
android:name="android.support.FILE_PROVIDER_PATHS"
android:resource="@xml/nebula_fileprovider_path" />
</provider>
com.mpaas.demo.nebula.provider
为 mPaaS 的代码示例信息,您需要根据自己的应用自行设置,并且不能设置为 com.mpaas.demo.nebula.provider
,以免与其他 mPaaS 应用产生冲突。新建 Java 类,实现 H5NebulaFileProvider,实现 getUriForFile 方法,在该方法中,调用上面实现的 FileProvider 生成 URI。
public class H5NebulaFileProviderImpl implements H5NebulaFileProvider {
private static final String TAG = "H5FileProviderImpl";
@Override
public Uri getUriForFile(File file) {
try {
return getUriForFileImpl(file);
} catch (Exception e) {
H5Log.e(TAG, e);
}
return null;
}
private static Uri getUriForFileImpl(File file) {
Uri fileUri = null;
if (Build.VERSION.SDK_INT >= 24) {
fileUri = NebulaDemoFileProvider.getUriForFile(LauncherApplicationAgent.getInstance().getApplicationContext(), "com.mpaas.demo.nebula.provider", file);
} else {
fileUri = Uri.fromFile(file);
}
return fileUri;
}
}
H5NebulaFileProvider
。
H5Utils.setProvider(H5NebulaFileProvider.class.getName(), new H5NebulaFileProviderImpl());
在文档使用中是否遇到以下问题
更多建议
匿名提交