jjzjj

带有 native C++ 库的 Android Instant App 未发布到运行 Android N 的设备/模拟器

coder 2023-12-14 原文

有没有办法让 Android Instant App 使用原生 C++ 库?

我正在尝试将 Android Instant App 发布到设备/模拟器,但我的 native C++ 库遇到了问题。它作为可安装的应用程序发布时很好,但在作为即时应用程序发布时无法找到库。

为了消除任何其他问题,我在 Android Studio 3.0 (Canary 1 171.4010489) 中开始了一个新项目使用新项目向导并选择以下设置:

第一页:

  • 包括已检查的 C++ 支持

第二页:

  • 已选择手机和平板电脑
  • 包括已选中的 Android Instant App 支持

第六页:

  • C++ 标准设置为“C++11”
  • 已检查异常支持 (-fexceptions)
  • 已检查运行时类型信息支持 (-frtti)

生成的项目将发布为可安装的应用程序(显示“Hello from C++”屏幕),但不是即时应用程序...它给出以下错误,它找不到库,这是相同的错误我进入了我实际应用的项目:

找不到“libnative-lib.so”

完整错误:

05-24 17:48:30.316 7519-7519/? E/AndroidRuntime: FATAL EXCEPTION: main
     Process: com.mycompany.instantapp, PID: 7519
     java.lang.UnsatisfiedLinkError: byc[DexPathList[[zip file "/data/user/0/com.google.android.instantapps.supervisor/files/atom-cache/com.mycompany.instantapp/atom-download--feature-1495662507463/feature.jar"],nativeLibraryDirectories=[/data/user/0/com.google.android.instantapps.supervisor/files/native-lib/com.mycompany.instantapp, /system/lib, /vendor/lib]]] couldn't find "libnative-lib.so"
     ...

我在下面粘贴相关的 gradle 文件(全部由 Android Studio 生成):

app/build.gradle:

apply plugin: 'com.android.application'

android {
    compileSdkVersion 25
    buildToolsVersion "26.0.0 rc2"

    defaultConfig {
        applicationId "com.mycompany.instantapp"
        minSdkVersion 23
        targetSdkVersion 25
        versionCode 1
        versionName "1.0"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    implementation project(':feature')
    implementation project(':base')
}

base/build.gradle:

apply plugin: 'com.android.feature'

android {
    compileSdkVersion 25
    buildToolsVersion "26.0.0 rc2"
    baseFeature true
    defaultConfig {
        minSdkVersion 23
        targetSdkVersion 25
        versionCode 1
        versionName "1.0"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    feature project(':feature')
    compile 'com.android.support:appcompat-v7:25.+'
    compile 'com.android.support.constraint:constraint-layout:1.0.2'
}

feature/build.gradle:

apply plugin: 'com.android.feature'

android {
    compileSdkVersion 25
    buildToolsVersion "26.0.0 rc2"
    defaultConfig {
        minSdkVersion 23
        targetSdkVersion 25
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
        externalNativeBuild {
            cmake {
                cppFlags "-std=c++11 -frtti -fexceptions"
            }
        }
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
    externalNativeBuild {
        cmake {
            path "CMakeLists.txt"
        }
    }
}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
        exclude group: 'com.android.support', module: 'support-annotations'
    })
    implementation project(':base')
    testCompile 'junit:junit:4.12'

}

instantapp/build.gradle:

apply plugin: 'com.android.instantapp'

dependencies {
    implementation project(':feature')
    implementation project(':base')
}

更新:

我已向 Google 提交问题:

链接:Google Issue Tracker

虽然我觉得实现这一目标的工具已经可用(Gradle、CMake、NDK 等)

也感谢@Anirudh 让我知道这是 Android N 上的一个已知问题。

可以在我的设备上发布不带 C++ 库的免安装应用吗?

是的...如果我创建一个新的 Android Studio 项目,只有 Include Android Instant App support,它会发布到我的 Samsung Galaxy 7S 并显示“Hello World!”屏幕。

发布已签名的 APK 是否有效?

生成签名的 APK 有效,经检查, native C++ 库与 feature-debug.apk bundle 在一起,但没有与 base-debug.apk bundle 在一起。这是我对 gradle 配置的期望,但没有解释为什么它不会发布到设备/模拟器。

我还没有尝试侧载这些 APK...但我怀疑这是否可能,因为从未安装 Instant App...例如:您甚至如何在侧载后启动它(单击 url ?)

将 C++ 库添加到两个 APK 是否有效?

我已经尝试将 externalNativeBuild gradle 属性添加到 base/build.gradlefeature/build.gradle 文件中,但仍然出现同样的错误。在生成签名的 APK 后,我通过检查 feature-debug.apkbase-debug.apk 验证了原生 C++ 库是否包含在两个 APK 中。

修改的base/build.gradle:

apply plugin: 'com.android.feature'

android {
    compileSdkVersion 25
    buildToolsVersion "26.0.0 rc2"
    baseFeature true
    defaultConfig {
        minSdkVersion 23
        targetSdkVersion 25
        versionCode 1
        versionName "1.0"
        externalNativeBuild {
            cmake {
                cppFlags "-std=c++11 -frtti -fexceptions"
            }
        }
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
    externalNativeBuild {
        cmake {
            path "../feature/CMakeLists.txt"
        }
    }
}

dependencies {
    feature project(':feature')
    compile 'com.android.support:appcompat-v7:25.+'
    compile 'com.android.support.constraint:constraint-layout:1.0.2'
}

最佳答案

Does publishing a signed APK work?

Android Studio 3.0 预览版生成签名的 APK 功能目前存在一个错误,即最终的 zip 不包含所有功能 apk。在每个功能模块的 gradle 文件中使用 Gradle SigningConfig 来签署您的功能 apk

Does adding the C++ library to both APKs work?

不需要。添加到基本功能 apk 应该足够了

实际崩溃是 NDK 支持 Android M/N 上的 Android Instant Apps 的已知问题。该应用程序适用于 Android O 模拟器

关于带有 native C++ 库的 Android Instant App 未发布到运行 Android N 的设备/模拟器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44169245/

有关带有 native C++ 库的 Android Instant App 未发布到运行 Android N 的设备/模拟器的更多相关文章

  1. ruby - 如何从 ruby​​ 中的字符串运行任意对象方法? - 2

    总的来说,我对ruby​​还比较陌生,我正在为我正在创建的对象编写一些rspec测试用例。许多测试用例都非常基础,我只是想确保正确填充和返回值。我想知道是否有办法使用循环结构来执行此操作。不必为我要测试的每个方法都设置一个assertEquals。例如:describeitem,"TestingtheItem"doit"willhaveanullvaluetostart"doitem=Item.new#HereIcoulddotheitem.name.shouldbe_nil#thenIcoulddoitem.category.shouldbe_nilendend但我想要一些方法来使用

  2. ruby - 如何每月在 Heroku 运行一次 Scheduler 插件? - 2

    在选择我想要运行操作的频率时,唯一的选项是“每天”、“每小时”和“每10分钟”。谢谢!我想为我的Rails3.1应用程序运行调度程序。 最佳答案 这不是一个优雅的解决方案,但您可以安排它每天运行,并在实际开始工作之前检查日期是否为当月的第一天。 关于ruby-如何每月在Heroku运行一次Scheduler插件?,我们在StackOverflow上找到一个类似的问题: https://stackoverflow.com/questions/8692687/

  3. ruby-on-rails - 如何在 ruby​​ 中使用两个参数异步运行 exe? - 2

    exe应该在我打开页面时运行。异步进程需要运行。有什么方法可以在ruby​​中使用两个参数异步运行exe吗?我已经尝试过ruby​​命令-system()、exec()但它正在等待过程完成。我需要用参数启动exe,无需等待进程完成是否有任何ruby​​gems会支持我的问题? 最佳答案 您可以使用Process.spawn和Process.wait2:pid=Process.spawn'your.exe','--option'#Later...pid,status=Process.wait2pid您的程序将作为解释器的子进程执行。除

  4. ruby - 无法运行 Rails 2.x 应用程序 - 2

    我尝试运行2.x应用程序。我使用rvm并为此应用程序设置其他版本的ruby​​:$rvmuseree-1.8.7-head我尝试运行服务器,然后出现很多错误:$script/serverNOTE:Gem.source_indexisdeprecated,useSpecification.Itwillberemovedonorafter2011-11-01.Gem.source_indexcalledfrom/Users/serg/rails_projects_terminal/work_proj/spohelp/config/../vendor/rails/railties/lib/r

  5. ruby-on-rails - 如何优雅地重启 thin + nginx? - 2

    我的瘦服务器配置了nginx,我的ROR应用程序正在它们上运行。在我发布代码更新时运行thinrestart会给我的应用程序带来一些停机时间。我试图弄清楚如何优雅地重启正在运行的Thin实例,但找不到好的解决方案。有没有人能做到这一点? 最佳答案 #Restartjustthethinserverdescribedbythatconfigsudothin-C/etc/thin/mysite.ymlrestartNginx将继续运行并代理请求。如果您将Nginx设置为使用多个上游服务器,例如server{listen80;server

  6. ruby - Sinatra:运行 rspec 测试时记录噪音 - 2

    Sinatra新手;我正在运行一些rspec测试,但在日志中收到了一堆不需要的噪音。如何消除日志中过多的噪音?我仔细检查了环境是否设置为:test,这意味着记录器级别应设置为WARN而不是DEBUG。spec_helper:require"./app"require"sinatra"require"rspec"require"rack/test"require"database_cleaner"require"factory_girl"set:environment,:testFactoryGirl.definition_file_paths=%w{./factories./test/

  7. ruby-on-rails - 无法让 rspec、spork 和调试器正常运行 - 2

    GivenIamadumbprogrammerandIamusingrspecandIamusingsporkandIwanttodebug...mmm...let'ssaaay,aspecforPhone.那么,我应该把“require'ruby-debug'”行放在哪里,以便在phone_spec.rb的特定点停止处理?(我所要求的只是一个大而粗的箭头,即使是一个有挑战性的程序员也能看到:-3)我已经尝试了很多位置,除非我没有正确测试它们,否则会发生一些奇怪的事情:在spec_helper.rb中的以下位置:require'rubygems'require'spork'

  8. ruby-on-rails - before_filter 运行多个方法 - 2

    是否有可能:before_filter:authenticate_user!||:authenticate_admin! 最佳答案 before_filter:do_authenticationdefdo_authenticationauthenticate_user!||authenticate_admin!end 关于ruby-on-rails-before_filter运行多个方法,我们在StackOverflow上找到一个类似的问题: https://

  9. 世界前沿3D开发引擎HOOPS全面讲解——集3D数据读取、3D图形渲染、3D数据发布于一体的全新3D应用开发工具 - 2

    无论您是想搭建桌面端、WEB端或者移动端APP应用,HOOPSPlatform组件都可以为您提供弹性的3D集成架构,同时,由工业领域3D技术专家组成的HOOPS技术团队也能为您提供技术支持服务。如果您的客户期望有一种在多个平台(桌面/WEB/APP,而且某些客户端是“瘦”客户端)快速、方便地将数据接入到3D应用系统的解决方案,并且当访问数据时,在各个平台上的性能和用户体验保持一致,HOOPSPlatform将帮助您完成。利用HOOPSPlatform,您可以开发在任何环境下的3D基础应用架构。HOOPSPlatform可以帮您打造3D创新型产品,HOOPSSDK包含的技术有:快速且准确的CAD

  10. ruby-on-rails - 如何在发布新的 Ruby 或 Rails 版本时收到通知? - 2

    有人知道在发布新版本的Ruby和Rails时收到电子邮件的方法吗?他们有邮件列表,RubyonRails有一个推特,但我不想听到那些随之而来的喧嚣,我只想知道什么时候发布新版本,尤其是那些有安全修复的版本。 最佳答案 从therailsblog获取提要.http://weblog.rubyonrails.org/feed/atom.xml 关于ruby-on-rails-如何在发布新的Ruby或Rails版本时收到通知?,我们在StackOverflow上找到一个类似的问题:

随机推荐