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
Related
I'm trying to write a capacitor plugin following this explanation. The Plugin should make use of Androids usageStatsManager.
With the code further below, I'm getting the following error in Android Studio:
error: cannot find symbol
UsageStatsManager usm = (UsageStatsManager) context.getSystemService(Context.USAGE_STATS_SERVICE);
symbol: variable context
location: class echoPlugin
So it seems somehow I'm not using context correctly.
My code in echoPlugin.java:
package com.echo.capacitor;
import com.getcapacitor.JSObject;
import com.getcapacitor.Plugin;
import com.getcapacitor.PluginMethod;
import com.getcapacitor.annotation.CapacitorPlugin;
import android.content.Context;
import android.util.Log;
import android.app.usage.UsageStats;
import android.app.usage.UsageStatsManager;
import java.util.Calendar;
import java.util.List;
#CapacitorPlugin(name = "echo")
public class echoPlugin extends Plugin {
#PluginMethod
public void getStats(Context call) {
Log.i("Method: ", "getStats");
UsageStatsManager usm = (UsageStatsManager) context.getSystemService(Context.USAGE_STATS_SERVICE);
long now = Calendar.getInstance().getTimeInMillis();
List<UsageStats> stats = usm.queryUsageStats(UsageStatsManager.INTERVAL_DAILY, 0, now);
JSObject ret = new JSObject();
ret.put("my Stats",stats);
call.resolve(ret);
}
}
I have to add that I'm a complete Java beginner. I'm normally doing Apps with Vue+Ionic+Capacitor, but because there is no implementation of the UsageStatsManager in Capacitor I'm trying to find a way to make it work.
Use getContext() instead of context
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 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.
Downloaded latest android Studio (android-studio-bundle-162.3871768-windows).
We were using com.android.sdklib.SdkManager class in our software but in latest Android Studio I'm not able to find the above mentioned class in any jar present inside the tools\lib folder.
Can anyone suggest what is the better alternative for this?
if you want to get a list of all the targets installed for knowledge, then you can just simply run the SDK manager. But since you want to call the getTargets() method, it means you need it for other purposes. check up the documentation on the android studio web page to find out if it the class you are searching for exists and the location of its jar file.
We can find the soure code of all the android classes in the below link.
https://javalibs.com/artifact/com.android.tools/sdklib?className=com.android.sdklib.tool.SdkManagerCli&source
SdkManagerCli class have equivalent method listPackages()which will list the packages.
We need to import sdklib-25.3.2.jar, repository-25.3.2.jar and common-25.3.2.jar to project.
Below is the working code for listing packages:-
import java.io.File;
import java.lang.reflect.Method;
import java.util.Collection;
import java.util.TreeSet;
import com.android.repository.Revision;
import com.android.repository.api.ConsoleProgressIndicator;
import com.android.repository.api.LocalPackage;
import com.android.repository.api.ProgressIndicator;
import com.android.repository.api.RepoManager;
import com.android.repository.impl.meta.RepositoryPackages;
import com.android.sdklib.repository.AndroidSdkHandler;
public class AndroidTesting {
public static void main(String[] args) {
listPackages();
}
private static void listPackages() {
AndroidSdkHandler mHandler = AndroidSdkHandler.getInstance(new
File("filePath")); //for eg:-sdk/platforms for API
ProgressIndicator progress = new ConsoleProgressIndicator();
RepoManager mRepoManager = mHandler.getSdkManager(progress);
mRepoManager.loadSynchronously(cacheExpirationMs, progress,
downloader, settings)(0, progress, null, null);
RepositoryPackages packages = mRepoManager.getPackages();
Collection<LocalPackage> locals = new TreeSet<LocalPackage>();
Collection<LocalPackage> localObsoletes = new
TreeSet<LocalPackage>();
for (LocalPackage local : packages.getLocalPackages().values()) {
if (local.obsolete()) {
localObsoletes.add(local);
} else {
locals.add(local);
}
Revision version = local.getVersion();
System.out.println(local.getDisplayName() + " "
+ local.getVersion() );
}
}
}
For several days I have been trying to implement SignalA in my Android-Project.
I've found out that I have to import the 3 Projects (parallel-basic-http-client, SignalA and SignalALongPolling) in Eclipse. After the import of parallel-basic-http-client, I have several errors. It seems that the origin of those errors is in the import statement:
import com.turbomanage.httpclient.AsyncCallback;
In the console, the following statement is listed:
[2013-12-03 09:03:45 - parallel-basic-http-client] WARNING: unable to write jarlist cache file C:\Users\Patrik\workspace\parallel-basic-http-client\bin\jarlist.cache
Below is the complete code for the understanding:
package com.zsoft.parallelhttpclient;
import android.os.AsyncTask;
import android.os.Build;
import com.turbomanage.httpclient.AsyncCallback;
import com.turbomanage.httpclient.AsyncHttpClient;
import com.turbomanage.httpclient.HttpRequest;
import com.turbomanage.httpclient.android.DoHttpRequestTask;
public class DoParallelHttpRequestTask extends DoHttpRequestTask {
public DoParallelHttpRequestTask(AsyncHttpClient httpClient,
AsyncCallback callback) {
super(httpClient, callback);
// TODO Auto-generated constructor stub
}
public void execute(HttpRequest httpRequest) {
if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.GINGERBREAD_MR1) {
super.execute(httpRequest);
} else {
super.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, httpRequest);
}
}
}
Can anyone help me?
I think there is a problem with the dependencies used by SignalA.
To make it easier to use SignalA I've published it on Maven Central.