【问题标题】:Cannot build React-native Marketing Cloud无法构建 React-native Marketing Cloud
【发布时间】:2021-04-19 15:04:40
【问题描述】:

在使用 ./gradlew assembleRelease 构建 react-native 应用时遇到问题

我已经安装了react-native-marketing-cloud

yarn add react-native-marketingcloudsdk

添加了 Maven 仓库

maven { url "https://salesforce-marketingcloud.github.io/MarketingCloudSDK-Android/repository" }

这是我的 MainApplication.java

package org.reactnative.example;

import android.app.Application;
import android.graphics.drawable.Drawable;
import android.content.Context;
import com.facebook.react.PackageList;
import com.facebook.react.ReactApplication;
import com.facebook.react.ReactInstanceManager;
import com.facebook.react.ReactNativeHost;
import com.facebook.react.ReactPackage;
import com.facebook.soloader.SoLoader;
import com.salesforce.marketingcloud.MarketingCloudConfig;
import com.salesforce.marketingcloud.MarketingCloudSdk;
import com.salesforce.marketingcloud.notifications.NotificationCustomizationOptions;
import java.lang.reflect.InvocationTargetException;
import java.util.List;
import android.util.Log;
import androidx.multidex.MultiDexApplication;

public class MainApplication extends MultiDexApplication implements ReactApplication {

  private final ReactNativeHost mReactNativeHost =
      new ReactNativeHost(this) {
        @Override
        public boolean getUseDeveloperSupport() {
          return BuildConfig.DEBUG;
        }

        @Override
        protected List<ReactPackage> getPackages() {
          @SuppressWarnings("UnnecessaryLocalVariable")
          List<ReactPackage> packages = new PackageList(this).getPackages();
          // Packages that cannot be autolinked yet can be added manually here, for example:
          // packages.add(new MyReactNativePackage());
          return packages;
        }

        @Override
        protected String getJSMainModuleName() {
          return "index";
        }
      };

  @Override
  public ReactNativeHost getReactNativeHost() {
    return mReactNativeHost;
  }

  @Override
  public void onCreate() {
    super.onCreate();
    MarketingCloudSdk.init(this,
      MarketingCloudConfig.builder()
        .setApplicationId("SECRET")
        .setAccessToken("SECRET")
        .setSenderId("SECRET")
        .setMarketingCloudServerUrl("SECRET")
        .setAnalyticsEnabled(true)
        .build(this),
      initializationStatus -> Log.e("INIT", initializationStatus.toString()));
    SoLoader.init(this, /* native exopackage */ false);
    initializeFlipper(this, getReactNativeHost().getReactInstanceManager());
  }
}

根据文档,使用该软件包就足够了

但出现此错误

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':react-native-marketingcloudsdk:verifyReleaseResources'.
> A failure occurred while executing com.android.build.gradle.internal.tasks.Workers$ActionFacade
   > Android resource linking failed
     /Users/apple/.gradle/caches/transforms-2/files-2.1/e7913c710c1c6a7686781b3ec2a08a9b/jetified-marketingcloudsdk-7.3.1/res/values/values.xml:161:5-169:13: AAPT: error: style attribute 'attr/layout_constraintWidth_max (aka com.salesforce.marketingcloud.reactnative:attr/layout_constraintWidth_max)' not found.
         
     /Users/apple/.gradle/caches/transforms-2/files-2.1/e7913c710c1c6a7686781b3ec2a08a9b/jetified-marketingcloudsdk-7.3.1/res/values/values.xml:194:5-204:13: AAPT: error: style attribute 'attr/layout_constraintWidth_max (aka com.salesforce.marketingcloud.reactnative:attr/layout_constraintWidth_max)' not found.
         
     /Users/apple/.gradle/caches/transforms-2/files-2.1/e7913c710c1c6a7686781b3ec2a08a9b/jetified-marketingcloudsdk-7.3.1/res/values/values.xml:213:5-221:13: AAPT: error: style attribute 'attr/layout_constraintWidth_max (aka com.salesforce.marketingcloud.reactnative:attr/layout_constraintWidth_max)' not found.
         
     /Users/apple/.gradle/caches/transforms-2/files-2.1/e7913c710c1c6a7686781b3ec2a08a9b/jetified-marketingcloudsdk-7.3.1/res/values/values.xml:238:5-241:13: AAPT: error: style attribute 'attr/layout_constraintDimensionRatio (aka com.salesforce.marketingcloud.reactnative:attr/layout_constraintDimensionRatio)' not found.
         
     /Users/apple/.gradle/caches/transforms-2/files-2.1/e7913c710c1c6a7686781b3ec2a08a9b/jetified-marketingcloudsdk-7.3.1/res/values/values.xml:250:5-260:13: AAPT: error: style attribute 'attr/layout_constraintWidth_max (aka com.salesforce.marketingcloud.reactnative:attr/layout_constraintWidth_max)' not found.
         
     /Users/apple/.gradle/caches/transforms-2/files-2.1/e7913c710c1c6a7686781b3ec2a08a9b/jetified-marketingcloudsdk-7.3.1/res/values/values.xml:272:5-280:13: AAPT: error: style attribute 'attr/layout_constraintWidth_max (aka com.salesforce.marketingcloud.reactnative:attr/layout_constraintWidth_max)' not found.
         
     /Users/apple/.gradle/caches/transforms-2/files-2.1/e7913c710c1c6a7686781b3ec2a08a9b/jetified-marketingcloudsdk-7.3.1/res/values/values.xml:295:5-298:13: AAPT: error: style attribute 'attr/layout_constraintDimensionRatio (aka com.salesforce.marketingcloud.reactnative:attr/layout_constraintDimensionRatio)' not found.
         
     /Users/apple/.gradle/caches/transforms-2/files-2.1/e7913c710c1c6a7686781b3ec2a08a9b/jetified-marketingcloudsdk-7.3.1/res/values/values.xml:315:5-325:13: AAPT: error: style attribute 'attr/layout_constraintWidth_max (aka com.salesforce.marketingcloud.reactnative:attr/layout_constraintWidth_max)' not found.
         

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.

* Get more help at https://help.gradle.org

Deprecated Gradle features were used in this build, making it incompatible with Gradle 7.0.
Use '--warning-mode all' to show the individual deprecation warnings.
See https://docs.gradle.org/6.2/userguide/command_line_interface.html#sec:command_line_warnings

BUILD FAILED in 2m 24s
576 actionable tasks: 523 executed, 53 up-to-date

这是那个文件/Users/apple/.gradle/caches/transforms-2/files-2.1/e7913c710c1c6a7686781b3ec2a08a9b/jetified-marketingcloudsdk-7.3.1/res/values/values.xml

不知道是什么问题

【问题讨论】:

    标签: android react-native salesforce-marketing-cloud


    【解决方案1】:

    解决方案 1

    您需要在项目的 android/build.gradle 中添加以下代码:

    subprojects {
        afterEvaluate {project ->
            if (project.hasProperty("android")) {
                android {
                    compileSdkVersion 27
                    buildToolsVersion "27.0.2"
                }
            }
        }
    }
    

    解决方案 2

    尝试运行它

    ./gradlew app:assembleRelease

    解决方案 3

    尝试从这个 fork 安装这个包

    "react-native-marketingcloudsdk": "git://github.com/ramoonpereira/react-native-marketingcloudsdk.git#b5416b311104845069cbfb43b10e12e2f482e90f"
    

    【讨论】:

    • 不幸的是无法使用这些选项中的任何一个来解决:(
    【解决方案2】:

    方法一

    实现'com.android.support.constraint:constraint-layout:1.1.3'

    如果这仍然给出错误然后尝试

    实现“androidx.constraintlayout:constraintlayout:2.0.4”

    方法二

    如果以上不起作用 在项目的 salesforcemarketingsdk gradle 文件中添加两行之一

    【讨论】:

    • 感谢您的回答。正在更新文档以包含此疏忽。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-08-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多