【问题标题】:Error while generating APK生成 APK 时出错
【发布时间】:2017-01-12 18:01:07
【问题描述】:

我正在尝试从 Android Studio 生成一个 APK 以将其发布到 Play 商店。 现在,当我生成 APK 时出现此错误:

我可以启动应用程序,但“生成 APK”不起作用,为了避免此错误,我将我的 Facebook 应用程序 ID 从我的 string.xml 复制到我的清单:

android:value="2132153153153535"

代替:

android:value="@string/facebook_app_id"

现在我可以生成 APK,但是当我从 playstore 启动我的应用时,我收到了这个错误:

无法启动活动 ComponentInfo{com.stable.giamma.sushichallenge/com.stable.giamma.sushichallenge.MenuActivity}:java.lang.IllegalArgumentException:context 和 applicationId 都必须为非 null

我可以通过反转我刚刚所做的修改来解决。

但如果我这样做,我将无法再次生成 APK .....

处理“facebook app id”并生成APK的正确方法是什么?

ps:我有 2 个 string.xml(一个用于英语,另一个用于意大利语)不知道是否会产生问题...

这是我的清单:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.asd.appname">

<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
o
<application
    android:allowBackup="true"
    android:icon="@mipmap/asd"
    android:label="@string/app_name"
    android:largeHeap="true"
    android:supportsRtl="true"
    android:theme="@style/AppTheme">
    <meta-data
        android:name="com.facebook.sdk.ApplicationId"
        android:value="@string/facebook_app_id" />   //THIS IS THE STRING THAT I MODIFY FOR AVOID THE FIRST ERROR

    <activity
        android:name="com.asd.MainActivity"
        android:label="@string/app_name"
        android:screenOrientation="landscape"
        android:theme="@style/AppTheme.NoActionBar" />
    <activity
        android:name="com.facebook.FacebookActivity"
        android:configChanges="keyboard|keyboardHidden|screenLayout|screenSize|orientation"
        android:label="@string/app_name"
        android:theme="@android:style/Theme.Translucent.NoTitleBar" />
    <activity
        android:name="com.asd.MenuActivity"
        android:screenOrientation="portrait"
        android:theme="@style/AppTheme.NoActionBar">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
    <activity
        android:name="com.asd.SushataActivity"
        android:label="@string/sushata"
        android:parentActivityName="com.asd.MenuActivity">
        <meta-data
            android:name="android.support.PARENT_ACTIVITY"
            android:value="com.asd.MenuActivity" />
    </activity>
    <activity
        android:name="com.asd.Sushata2Activity"
        android:label="@string/sushata2"
        android:parentActivityName="com.asd.SushataActivity">
        <meta-data
            android:name="android.support.PARENT_ACTIVITY"
            android:value="com.asd.SushataActivity" />
    </activity>
    <activity
        android:name="com.asd.Leaderboard"
        android:screenOrientation="portrait"
        android:theme="@style/AppTheme.NoActionBar"></activity>
</application>

【问题讨论】:

  • 显示您的清单代码
  • 您是否尝试过在末尾定义元数据标记,我的意思是在LeaderBoard Activity 下方。试一试。
  • 是同样的错误,无法生成apk
  • 我用更多的行更新了第一个错误
  • 您是否在 Activity 中初始化了 facebook sdk

标签: android-studio google-play apk


【解决方案1】:

我补充说:

tools:ignore="ManifestResource"

正确的代码是:

<meta-data
        android:name="com.facebook.sdk.ApplicationId"
        android:value="@string/facebook_app_id"
        tools:ignore="ManifestResource"/>

现在看来工作了,我发现这篇 stackoverflow 帖子很有帮助:link

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2018-03-08
    • 1970-01-01
    • 1970-01-01
    • 2017-10-15
    • 2017-05-10
    相关资源
    最近更新 更多