Android “无法链接”;反应本机后台计时器“;安卓软件包
使用react native cli 0.62构建需要后台计时器的android应用程序。因此,我使用的是上述软件包。自动链接失败,因此请尝试上述软件包自述文件中提到的android手动链接过程Android “无法链接”;反应本机后台计时器“;安卓软件包,android,reactjs,react-native,Android,Reactjs,React Native,使用react native cli 0.62构建需要后台计时器的android应用程序。因此,我使用的是上述软件包。自动链接失败,因此请尝试上述软件包自述文件中提到的android手动链接过程 我应该添加android/app/build.gradle: 但我现有的文件如下所示: // Top-level build file where you can add configuration options common to all sub-projects/modules. buildsc
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
ext {
buildToolsVersion = "28.0.3"
minSdkVersion = 16
compileSdkVersion = 28
targetSdkVersion = 28
}
repositories {
google()
jcenter()
}
dependencies {
classpath("com.android.tools.build:gradle:3.5.2")
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
mavenLocal()
maven {
// All of React Native (JS, Obj-C sources, Android binaries) is installed from npm
url("$rootDir/../node_modules/react-native/android")
}
maven {
// Android JSC is installed from npm
url("$rootDir/../node_modules/jsc-android/dist")
}
google()
jcenter()
maven { url 'https://www.jitpack.io' }
}
}
+导入com.ocetnik.timer.BackgroundTimerPackage;
@凌驾
受保护的列表getPackages(){
返回数组.asList(
+新的BackgroundTimerPackage()
);
}
但我现有的文件如下所示:
@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;
}
@覆盖
受保护的列表getPackages(){
@抑制警告(“不必要的局部变量”)
List packages=new PackageList(this).getPackages();
//无法自动链接但可以在此处手动添加的包,例如:
//packages.add(新的MyReactNativePackage());
退货包裹;
}
如何包含这两个代码部分?android项目中有两个build.gradle。您已打开根级别的android/build.gradle文件。您必须在app-levelandroid/app/build.gradle中添加依赖项。App-level build.gradle文件的末尾将有一个依赖项部分 对于第二部分,您必须在此行取消注释后导入包,并进行如下修改:
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
ext {
buildToolsVersion = "28.0.3"
minSdkVersion = 16
compileSdkVersion = 28
targetSdkVersion = 28
}
repositories {
google()
jcenter()
}
dependencies {
classpath("com.android.tools.build:gradle:3.5.2")
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
mavenLocal()
maven {
// All of React Native (JS, Obj-C sources, Android binaries) is installed from npm
url("$rootDir/../node_modules/react-native/android")
}
maven {
// Android JSC is installed from npm
url("$rootDir/../node_modules/jsc-android/dist")
}
google()
jcenter()
maven { url 'https://www.jitpack.io' }
}
}
packages.add(newbackgroundtimerpackage()) 谢谢。这对我有用。Alos,我不需要在MainApplication.java中添加代码。当我添加它时,它显示一个错误,它已经添加了两次(可能是通过自动链接添加的),所以我删除了它。
@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;
}