15

我已经在我的项目中配置了构建变体,applicationIdSuffix以便我可以在我的设备上安装调试和发布版本。这是我的build.gradle(相关部分):

 buildTypes {
        debug {
            buildConfigField "String", "BASE_URL", '"http://dev.xyz.com"'

            applicationIdSuffix ".debug"
        }
        release {
            buildConfigField "String", "BASE_URL", '"http://api.xyz.com"'
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }

但是当我尝试安装两者时,它失败了。我尝试了不同的方法:

1.生成调试和发布apk,并将它们转移到我的手机存储中。第一个安装,第二个给出错误“未安装应用程序” - 没有更多信息。无论我先安装哪个版本,这都是一样的。

2.从存储安装调试版本,然后尝试从play store安装release版本,但play store给出错误:

无法安装应用程序错误代码:-505。

3.从商店安装发布版本,然后尝试从 android studio 运行项目,这是我的“运行”日志:

    Launching app
    $ adb push D:\myPROJECTS\MyApp\app\build\outputs\apk\app-debug.apk /data/local/tmp/com.example.myapp.debug
    $ adb shell pm install -r "/data/local/tmp/com.example.myapp.debug"
    java.lang.UnsatisfiedLinkError: No implementation found for java.lang.String android.os.SystemProperties.native_get(java.lang.String) (tried Java_android_os_SystemProperties_native_1get and Java_android_os_SystemProperties_native_1get__Ljava_lang_String_2)
      at android.os.SystemProperties.native_get(Native Method)
      at android.os.SystemProperties.get(SystemProperties.java:52)
      at android.os.Environment$UserEnvironment.<init>(Environment.java:123)
      at android.os.Environment.initForCurrentUser(Environment.java:98)
      at android.os.Environment.<clinit>(Environment.java:92)
      at android.os.Environment.getLegacyExternalStorageDirectory(Environment.java:597)
      at android.os.Debug.<clinit>(Debug.java:103)
      at android.ddm.DdmHandleHello.handleHELO(DdmHandleHello.java:164)
      at android.ddm.DdmHandleHello.handleChunk(DdmHandleHello.java:91)
      at org.apache.harmony.dalvik.ddmc.DdmServer.dispatch(DdmServer.java:171)
    java.lang.UnsatisfiedLinkError: android.os.Debug
      at android.ddm.DdmHandleHello.handleFEAT(DdmHandleHello.java:176)
      at android.ddm.DdmHandleHello.handleChunk(DdmHandleHello.java:93)
      at org.apache.harmony.dalvik.ddmc.DdmServer.dispatch(DdmServer.java:171)
    java.lang.UnsatisfiedLinkError: android.os.Debug
      at android.ddm.DdmHandleProfiling.handleMPRQ(DdmHandleProfiling.java:187)
      at android.ddm.DdmHandleProfiling.handleChunk(DdmHandleProfiling.java:88)
      at org.apache.harmony.dalvik.ddmc.DdmServer.dispatch(DdmServer.java:171)
    Aborted 

    $ adb shell am start -n "com.example.myapp.debug/com.example.myapp.LoginActivity" -a android.intent.action.MAIN -c android.intent.category.LAUNCHER
    Error while executing: am start -n "com.example.myapp.debug/com.example.myapp.LoginActivity" -a android.intent.action.MAIN -c android.intent.category.LAUNCHER
    Starting: Intent { act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] cmp=com.example.myapp.debug/com.example.myapp.LoginActivity }
    Error type 3
    Error: Activity class {com.example.myapp.debug/com.example.myapp.LoginActivity} does not exist.

    Error while Launching activity

知道发生了什么吗?

更新:不知道它是否有帮助,但这是我声明我的启动器活动的方式androidmanifest.xml

<activity
    android:name=".LoginActivity"
    android:label="@string/app_name"
    android:screenOrientation="portrait"
    android:theme="@style/AppTheme.Launcher">
    <intent-filter>
        <action android:name="android.intent.action.MAIN" />
        <category android:name="android.intent.category.LAUNCHER" />
    </intent-filter>
</activity>
4

2 回答 2

7

好吧,我知道发生了什么。

我实际上是在为调试变体(Build > Build APK)创建一个未签名的 apk。但我必须使用(Build > Generate Signed APK)然后从选项中选择调试变体。

在此处输入图像描述

此外,在我的设备上运行项目时,gradle 会生成一个未签名的 apk。所以这也行不通。也就是说 - 除非我按照此答案SigningConfigs中的说明进行配置。

于 2016-08-29T13:51:54.227 回答
4

为什么不使用构建类型,而不是使用产品风味呢?这是有关如何执行此操作以及您当前尝试执行的操作的文档的链接。希望这可以帮助。

于 2016-08-28T22:02:16.253 回答