I was getting a successful build with android in React Native until I added these:
"appcenter-analytics": "2.1.0",
"appcenter-crashes": "2.1.0",
I am on:
"react": "16.8.6",
"react-native": "0.60.4",
The error is:
Error: Command failed: ./gradlew app:installDebug
-PreactNativeDevServerPort=8081 Note: /Users/danale/Projects/NFIBEngage/node_modules/react-native-sentry/android/src/main/java/io/sentry/RNSentryModule.java
uses or overrides a deprecated API. Note: Recompile with
-Xlint:deprecation for details. Note: Some input files use unchecked or unsafe operations. Note: Recompile with -Xlint:unchecked for
details.
/Users/danale/Projects/NFIBEngage/android/app/build/generated/rncli/src/main/java/com/facebook/react/PackageList.java:60:
error: cannot find symbol
new AppCenterReactNativeAnalyticsPackage(MainApplication.this, getResources().getString(R.string.appCenterAnalytics_whenToEnableAnalytics)),
^ symbol: class MainApplication location: class PackageList
/Users/danale/Projects/NFIBEngage/android/app/build/generated/rncli/src/main/java/com/facebook/react/PackageList.java:60:
error: cannot find symbol
new AppCenterReactNativeAnalyticsPackage(MainApplication.this, getResources().getString(R.string.appCenterAnalytics_whenToEnableAnalytics)),
^ symbol: variable appCenterAnalytics_whenToEnableAnalytics
location: class string
/Users/danale/Projects/NFIBEngage/android/app/build/generated/rncli/src/main/java/com/facebook/react/PackageList.java:61:
error: cannot find symbol
new AppCenterReactNativeCrashesPackage(MainApplication.this, getResources().getString(R.string.appCenterCrashes_whenToSendCrashes)),
^ symbol: class MainApplication location: class PackageList
/Users/danale/Projects/NFIBEngage/android/app/build/generated/rncli/src/main/java/com/facebook/react/PackageList.java:61:
error: cannot find symbol
new AppCenterReactNativeCrashesPackage(MainApplication.this, getResources().getString(R.string.appCenterCrashes_whenToSendCrashes)),
^ symbol: variable appCenterCrashes_whenToSendCrashes location:
class string 4 errors
FAILURE: Build failed with an exception.
What went wrong: Execution failed for task ':app:compileDebugJavaWithJavac'.
Compilation failed; see the compiler error output for details.
Apparently there is this android/app/build/generated/rncli/src/main/java/com/facebook/react/PackageList.java file that did not exist with the legacy version of this application:
package com.facebook.react;
import android.app.Application;
import android.content.Context;
import android.content.res.Resources;
import com.facebook.react.ReactPackage;
import com.facebook.react.shell.MainReactPackage;
import java.util.Arrays;
import java.util.ArrayList;
import com.nfibengage.BuildConfig;
import com.nfibengage.R;
// #react-native-community/async-storage
import com.reactnativecommunity.asyncstorage.AsyncStoragePackage;
// appcenter-analytics
import com.microsoft.appcenter.reactnative.analytics.AppCenterReactNativeAnalyticsPackage;
// appcenter-crashes
import com.microsoft.appcenter.reactnative.crashes.AppCenterReactNativeCrashesPackage;
// react-native-sentry
import io.sentry.RNSentryPackage;
// react-native-splash-screen
import org.devio.rn.splashscreen.SplashScreenReactPackage;
public class PackageList {
private Application application;
private ReactNativeHost reactNativeHost;
public PackageList(ReactNativeHost reactNativeHost) {
this.reactNativeHost = reactNativeHost;
}
public PackageList(Application application) {
this.reactNativeHost = null;
this.application = application;
}
private ReactNativeHost getReactNativeHost() {
return this.reactNativeHost;
}
private Resources getResources() {
return this.getApplication().getResources();
}
private Application getApplication() {
if (this.reactNativeHost == null) return this.application;
return this.reactNativeHost.getApplication();
}
private Context getApplicationContext() {
return this.getApplication().getApplicationContext();
}
public ArrayList<ReactPackage> getPackages() {
return new ArrayList<>(Arrays.<ReactPackage>asList(
new MainReactPackage(),
new AsyncStoragePackage(),
new AppCenterReactNativeAnalyticsPackage(MainApplication.this, getResources().getString(R.string.appCenterAnalytics_whenToEnableAnalytics)),
new AppCenterReactNativeCrashesPackage(MainApplication.this, getResources().getString(R.string.appCenterCrashes_whenToSendCrashes)),
new RNSentryPackage(),
new SplashScreenReactPackage()
));
}
}
The MainApplication.java file is inside of android/main/java/com/nfibengage/MainApplication.java:
package com.nfibengage;
import android.app.Application;
import android.util.Log;
import com.facebook.react.PackageList;
import com.facebook.hermes.reactexecutor.HermesExecutorFactory;
import com.facebook.react.bridge.JavaScriptExecutorFactory;
import com.facebook.react.ReactApplication;
import com.facebook.react.ReactNativeHost;
import com.facebook.react.ReactPackage;
import com.facebook.soloader.SoLoader;
import java.util.List;
public class MainApplication extends Application 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();
SoLoader.init(this, /* native exopackage */ false);
}
}
I tried importing it into PackageList.java like so:
import com.nfibengage.MainApplication;
but I continue to get the same error. If anyone can walk me through where did this PackageList.java file come from and how do I get this working again short of just completely removing appcenter-analytics and appcenter-crashes.
Please make sure your installation order is the same as the following.
Add the App Center SDK modules
npm install appcenter appcenter-analytics appcenter-crashes --save-exact
or
yarn add appcenter appcenter-analytics appcenter-crashes --exact
Integrate the SDK automatically
react-native link appcenter
react-native link appcenter-analytics
react-native link appcenter-crashes
App Center SDK does not set up mocks automatically for App Center modules during the linking process. If you are using Jest test framework in your application and experience errors caused by the App Center SDK while running tests with Jest, add the following to the jest section of package.json file (include only modules in use):
"setupFiles": [
"<rootDir>/node_modules/appcenter/test/AppCenterMock.js",
"<rootDir>/node_modules/appcenter-analytics/test/AppCenterAnalyticsMock.js",
"<rootDir>/node_modules/appcenter-crashes/test/AppCenterCrashesMock.js",
"<rootDir>/node_modules/appcenter-push/test/AppCenterPushMock.js"
]
Edit the project's android/app/src/main/assets/appcenter-config.json and replace the YOUR_APP_SECRET placeholder value with your App Center project's application secret.
do one think only
goto your folder structure.
2.Add a file yarn-error.log
there will not be any problem your project will start well.
Related
Please HELP!!
I'm working on an app in react-native that involves using a native Calendar module. I'm trying to register this module with react native and I keep getting this error.
This is how I've registered the module in MainApplication.java:
#Override
protected List<ReactPackage> getPackages() {
List<ReactPackage> packages = new PackageList(this).getPackages();
packages.add(new ModuleRegistryAdapter(mModuleRegistryProvider));
packages.add(new MyAppPackage());
return packages;
}
This is the MyAppPackage.java file I've created using the tutorial here, https://reactnative.dev/docs/native-modules-android#register-the-module-android-specific.:
package com.chowtime; // replace your-app-name with your app’s name
import com.facebook.react.ReactPackage;
import com.facebook.react.bridge.NativeModule;
import com.facebook.react.bridge.ReactApplicationContext;
import com.facebook.react.uimanager.ViewManager;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
public class MyAppPackage implements ReactPackage {
#Override
public List<ViewManager> createViewManagers(ReactApplicationContext reactContext) {
return Collections.emptyList();
}
#Override
public List<NativeModule> createNativeModules(
ReactApplicationContext reactContext) {
List<NativeModule> modules = new ArrayList<>();
modules.add(new CalendarModule(reactContext));
return modules;
}
}
Note: This app was previously created using the managed-workflow on expo and was ejected to the bare workflow. This is the directory for the relevant files:
I came across this same error. It seems like the docs on how to create/use native modules in react native are missing a step.
In the MainApplication.java file you need to import 'MyAppPackage'.
import com.your-app-name.MyAppPackage;
Without importing it the 'MainApplication' file it won't know what MyAppPackage is referring to hence the cannot find symbol error.
Is this as simple as an import problem?
I noticed your MyAppPackage class is defined here:
package com.chowtime; // replace your-app-name with your app’s name
But your MainApplication error message seems indicate a sub-package, specifically "chowtime.chowtime". Did you mean for both chowtimes?
com.chowtime.chowtime.MainApplication
Trying to create native module for react-native. I have all the dependencies needed and I followed the instructions user com mobile sdk installation
in project/android/build.gradle
allprojects {
repositories {
…
maven {
url 'https://android-sdk.user.com'
}
}
}
in project/android/app/build.gradle
dependencies {
implementation 'com.user:android-sdk:1.0.0'
}
then i created file in project/app/src/main/java/com/my_app/UserComModule.java
package com.my_app;
import com.facebook.react.bridge.NativeModule;
import com.facebook.react.bridge.ReactApplicationContext;
import com.facebook.react.bridge.ReactContext;
import com.facebook.react.bridge.ReactContextBaseJavaModule;
import com.facebook.react.bridge.ReactMethod;
import java.util.Map;
import java.util.HashMap;
import com.user.UserCom;
public class UserComModule extends ReactContextBaseJavaModule {
private static ReactApplicationContext reactContext;
#Override
public void onCreate() {
super.onCreate();
new UserCom.Builder(
this,
"api_secret", //your api secret key generated in User.com webpanel details
"https://<your_app_subdomain>.user.com"
)
.trackAllActivities(true) // false by default
.openLinksInChromeCustomTabs(true) // true by default
.setCustomTabsBuilder(getCustomTabsBuilder())
.build();
}
}
When i run i get: cannot find symbol import com.user.UserCom;
You're importing UserCom, and that module is not availabe, as you've mentioned you had created the file UserComModule in that directory, either create UserCom class or delete this line from UserComModule
import com.user.UserCom;
I am building my android app with react native using react-native run-android
However, after that I am receiving the following error:
* What went wrong:
Execution failed for task ':app:preDexDebug'.
> com.android.ide.common.process.ProcessException: org.gradle.process.internal.ExecException: Process 'command '/Library/Java/JavaVirtualMachines/jdk1.7.0_67.jdk/Contents/Home/bin/java'' finished with non-zero exit value 1
After looking at multiple solutions and research, I ran a gradle clean and ran it again. Then I set up gradle daemon.
react-native run-android failed with error: Execution failed for task ':app:dexDebug'
Now the build time is faster; however, the error is still occurring.
What is the reason for this problem? And how can this be resolved?
Here is my MainApplication.java if needed
package com.wosyldelivery;
import android.app.Application;
import android.util.Log;
import com.facebook.react.ReactApplication;
import com.microsoft.codepush.react.CodePush;
import com.oblador.vectoricons.VectorIconsPackage;
import com.facebook.react.ReactInstanceManager;
import com.facebook.react.ReactNativeHost;
import com.facebook.react.ReactPackage;
import com.facebook.react.shell.MainReactPackage;
import java.util.Arrays;
import java.util.List;
public class MainApplication extends Application implements ReactApplication {
private final ReactNativeHost mReactNativeHost = new ReactNativeHost(this) {
#Override
public boolean getUseDeveloperSupport() {
return BuildConfig.DEBUG;
}
#Override
protected List<ReactPackage> getPackages() {
return Arrays.<ReactPackage>asList(
new MainReactPackage(),
new VectorIconsPackage()
);
}
#Override
protected String getJSBundleFile() {
return CodePush.getJSBundleFile();
}
};
#Override
public ReactNativeHost getReactNativeHost() {
return mReactNativeHost;
}
}
I am trying to build the tests using gradle in the project.
On building the tests, I am getting error ->
:compileTestJava/home/vibhcool/Documents/github/loklak_server/test/org/loklak/harvester/TwitterScraperTest.java:28: error: cannot find symbol
#TEST
^
symbol: class TEST
location: class TwitterScraperTest
1 error
FAILED
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':compileTestJava'.
The file in which I am getting error ->
package org.loklak.harvester;
import java.io.File;
import java.io.IOException;
import org.junit.After;
import org.junit.Before;
import org.loklak.harvester.TwitterScraper;
import org.junit.Test;
import static org.junit.Assert.assertEquals;
public class TwitterScraperTest {
#TEST
public void test_prepareSearchURL() {
String url;
String[] query = {"q1", "q2", "q3", };
String[] out_url = {"url1", "url2", "url3"};
for (int i = 0; i < query.length; i++) {
url = TwitterScraper.prepareSearchURL(query[i]);
assertEquals(url, out_url[i]);
}
}
}
When I comment #TEST in the file, gradle successfully builds the tests.
I have googled a lot but, not able to get the error.
I am using junit 4.10
It should be :
#Test
public void test_prepareSearchURL() {
...
}
and not
#TEST
public void test_prepareSearchURL() {
..
}
You can take a look on how to get started with Junit here.
I tried to run an android project in Cordova with self-build plugin,
Heres the code in JS and java for the plugin
var cordova = require('cordova');
var Carrier = function() {};
Carrier.prototype.getCarrierCode = function(success, error) {
cordova.exec(success, error, 'CarrierPlugin', 'getCarrierCode', []);
};
var carrier = new Carrier();
module.exports = carrier;
this is the java code:
import org.apache.cordova.CordovaPlugin;
import org.apache.cordova.CallbackContext;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import java.util.Date;
import android.app.Activity;
import android.database.Cursor;
import android.os.Bundle;
import android.provider.CallLog;
import android.content.ContentResolver;
public class CarrierPlugin extends CordovaPlugin{
public static final String TAG = "CarrierPlugin";
public static final String ACTION_GET_CARRIER_CODE = "getCarrierCode";
//public TelephonyManager tm;
#Override
public void initialize(CordovaInterface cordova, CordovaWebView webView) {
// TODO Auto-generated method stub
super.initialize(cordova, webView);
}
#Override
public boolean execute(String action, CordovaArgs args,
CallbackContext callbackContext) throws JSONException{
callbackContext.success("run it");
return true;
}
}
the error I got is "cannot find symbol :"
the strange thing is that, even if I change the code in the CarrierPlugin.java(delete the JSONException in line 16), it reported the same error.
My Eclipse says, you should import CordovaInterface, CordovaWebView and CordovaArgs.
And you might be missing package declaration as well, depending wherever you want to put your plugin's java files, such as:
package com.yourdomain.etc in the very first line of your Java file.