[英]Cannot build React-native Marketing Cloud
使用./gradlew assembleRelease
構建 react-native 應用時出現問題
我已經安裝了react-native-marketing-cloud package
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());
}
}
根據文檔,這足以使用 package
但是得到這個錯誤
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
不確定是什么問題
方法一
實施 'com.android.support.constraint:constraint-layout:1.1.3'
如果仍然出現錯誤,請嘗試
實施“androidx.constraintlayout:constraintlayout:2.0.4”
方法二
如果以上不起作用在您的項目中添加 salesforcemarketingsdk gradle 文件中的兩行之一
您需要在項目的 android/build.gradle 中添加以下代碼:
subprojects {
afterEvaluate {project ->
if (project.hasProperty("android")) {
android {
compileSdkVersion 27
buildToolsVersion "27.0.2"
}
}
}
}
嘗試運行它
./gradlew app:assembleRelease
嘗試從這個 fork 安裝這個 package
"react-native-marketingcloudsdk": "git://github.com/ramoonpereira/react-native-marketingcloudsdk.git#b5416b311104845069cbfb43b10e12e2f482e90f"
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.