Background: I'm trying to make a simple with RxPermissions .. I created a new project with the bellow code/setup but when I launch the app I got a dialog with the message "unfortunately package installer has stopped"
gradle.build
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:24.1.1'
compile 'com.tbruyelle.rxpermissions:rxpermissions:0.7.0#aar'
compile 'io.reactivex:rxandroid:1.2.1'
// Because RxAndroid releases are few and far between, it is recommended you also
// explicitly depend on RxJava's latest version for bug fixes and new features.
compile 'io.reactivex:rxjava:1.1.6'
}
MainActivity.java
public class MainActivity extends Activity {
#Override protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
// Must be done during an initialization phase like onCreate
((Button) findViewById(R.id.button)).setOnClickListener(new View.OnClickListener() {
#Override public void onClick(View view) {
RxPermissions.getInstance(MainActivity.this)
.request(Manifest.permission.CAMERA)
.subscribe(new Action1<Boolean>() {
#Override public void call(Boolean aBoolean) {
}
});
}
});
}
}
I forgot to declare the permission Manifest.permission.CAMERA in the manifest.
Related
I'm Trying to read data from Firebase but app crashes on generate error in logcat below. I have tried all solutions available on stackoverflow and other sites but still i m failed to solve this issue I have made changes and shared necessary code here
.gradle Project (dependencies)
dependencies {
classpath 'com.android.tools.build:gradle:3.3.2'
classpath 'com.google.gms:google-services:4.2.0'
}
app.gradle (dependencies)
dependencies {
implementation fileTree(include: ['*.jar'], dir: 'libs')
implementation 'com.android.support:appcompat-v7:28.0.0'
implementation 'com.android.support:animated-vector-drawable:28.0.0'
implementation 'com.android.support.constraint:constraint-layout:1.1.3'
implementation 'com.google.firebase:firebase-database:17.0.0'
implementation 'com.google.firebase:firebase-core:16.0.9'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-
core:3.0.2'
implementation 'com.android.support:support-annotations:28.0.0'
implementation 'com.android.support:support-v4:28.0.0'
}
main.java
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
FirebaseApp.initializeApp(getApplicationContext());
initViews();
mBtn.setOnClickListener(this::readData);
}
public void readData(View view) {
mRef.addValueEventListener(new ValueEventListener() {
#Override
public void onDataChange(#NonNull DataSnapshot dataSnapshot) {
String data = dataSnapshot.getValue(String.class);
setT.setText(data);
}
#Override
public void onCancelled(#NonNull DatabaseError databaseError) {
setT.setText("Sorry Data");
}
});
}
private void initViews() {
mBtn = findViewById(R.id.mBtn);
setT = findViewById(R.id.setT);
}
}
Logcat
try replace your database implementation version 17.0.0 to this version
implementation 'com.google.firebase:firebase-database:16.0.5'
and it will work
App just opens and closes after running from android studio on android studio.
Following warning is also shown :
The app gradle file must have a dependency on com.google.firebase:firebase-core for Firebase services to work as intended.
I tried making making the app from a tutorial, the app is compiled successfully but just opens and closes when it is run on android phone.
build.gradle
apply plugin: 'com.android.application'
android {
compileSdkVersion 27
defaultConfig {
applicationId "com.example.hp.chatapp"
minSdkVersion 16
targetSdkVersion 27
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.android.support:appcompat-v7:27.1.1'
implementation 'com.android.support.constraint:constraint-layout:1.1.2'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
//add library
implementation 'com.android.support:design:27.1.1'
implementation 'com.firebaseui:firebase-ui-database:3.2.2'
implementation 'com.google.firebase:firebase-auth:10.2.1'
implementation 'com.firebaseui:firebase-ui-auth:3.2.2'
implementation "com.google.android.gms:play-services-gcm:10.2.1"
}
apply plugin: 'com.google.gms.google-services'
build.gradle
buildscript {
repositories {
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.1.3'
classpath 'com.google.gms:google-services:4.0.2'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
Main activity is
public class MainActivity extends AppCompatActivity {
private static int SIGN_IN_REQUEST_CODE= 1;
private FirebaseListAdapter<ChatMessage> adapter;
RelativeLayout activity_main;
FloatingActionButton fab;
#Override
public boolean onOptionsItemSelected(MenuItem item) {
if(item.getItemId()==R.id.menu_sign_out){
AuthUI.getInstance().signOut(this).addOnCompleteListener(new
OnCompleteListener<Void>() {
#Override
public void onComplete(#NonNull Task<Void> task) {
Snackbar.make(activity_main,"You have been signed out.",Snackbar.LENGTH_SHORT).show();
finish();
}
});
}
return true;
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.main_menu,menu);
return true;
}
#Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if(requestCode==RESULT_OK){
Snackbar.make(activity_main,"Successfully signed in.Welcome !",Snackbar.LENGTH_SHORT).show();
displayChatMessage();
}
else {
Snackbar.make(activity_main,"We couldn't sign you in.Please try again later",Snackbar.LENGTH_SHORT).show();
finish();
}
}
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
activity_main=(RelativeLayout)findViewById(R.id.activity_main);
fab=(FloatingActionButton)findViewById(R.id.fab);
fab.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
EditText input= (EditText)findViewById(R.id.input);
FirebaseDatabase.getInstance().getReference().push().setValue(new ChatMessage(input.getText().toString(),FirebaseAuth.getInstance().getCurrentUser().getEmail()));
input.setText("");
}
});
//check if not sign in then navigate signin page
if(FirebaseAuth.getInstance().getCurrentUser()==null)
{
startActivityForResult(AuthUI.getInstance().createSignInIntentBuilder().build(),SIGN_IN_REQUEST_CODE);
}
else {
Snackbar.make(activity_main,"Welcome "+FirebaseAuth.getInstance().getCurrentUser().getEmail(),Snackbar.LENGTH_SHORT).show();
}
//load content
displayChatMessage();
}
private void displayChatMessage() {
ListView listOfMessage=(ListView)findViewById(R.id.list_of_message);
//Suppose you want to retrieve "chats" in your Firebase DB:
Query query =
FirebaseDatabase.getInstance().getReference().child("chats");
//The error said the constructor expected FirebaseListOptions - here you create them:
FirebaseListOptions<ChatMessage> options = new FirebaseListOptions.Builder<ChatMessage>()
.setQuery(query, ChatMessage.class)
.setLayout(android.R.layout.simple_list_item_1)
.build();
//Finally you pass them to the constructor here:
adapter = new FirebaseListAdapter<ChatMessage>(options){
#Override
protected void populateView(View v, ChatMessage model, int position) {
// Get references to the views of message.xml
TextView messageText = (TextView)v.findViewById(R.id.message_text);
TextView messageTime = (TextView)v.findViewById(R.id.message_time);
TextView messageUser=(TextView)findViewById(R.id.message_user);
messageText.setText(model.getMessageText());
messageUser.setText(model.getMessageUser());
messageTime.setText(DateFormat.format("dd-MM-yyyy (HH:mm:ss)",model.getMessageTime()));
}
};
listOfMessage.setAdapter(adapter);
}
}
EDITED
log error from logcat
08-03 02:00:47.736 3199-3199/com.example.hp.chatapp E/HAL: PATH3 /odm/lib64/hw/gralloc.qcom.so
PATH2 /vendor/lib64/hw/gralloc.qcom.so
PATH1 /system/lib64/hw/gralloc.qcom.so
PATH3 /odm/lib64/hw/gralloc.msm8953.so
08-03 02:00:47.737 3199-3199/com.example.hp.chatapp E/HAL: PATH2 /vendor/lib64/hw/gralloc.msm8953.so
PATH1 /system/lib64/hw/gralloc.msm8953.so
Try using the Firebase tool within Android Studio. Select the service you want to integrate, and follow the step-by-step instructions.
Assuming all other setup is correct, the error is self explanatory. You need to add a dependency on Firebase Core in your app gradle file under dependencies:
implementation 'com.google.firebase:firebase-core:16.0.1'
You might also want to check out the link below for any missing steps.
Add Firebase to Android Project
I use batch.com for push notification service, and i got error when initializing it.
this my activity class:
public class MainActivity extends AppCompatActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
#Override
protected void onStart() {
super.onStart();
Batch.onStart(this);
}
}
i got this error when activity launch :
FATAL EXCEPTION: main Process: com.negin.batch_test, PID: 687
java.lang.NoClassDefFoundError: com.batch.android.BatchPushInstanceIDService
this is my gradle :
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.android.support:appcompat-v7:26.1.0'
implementation 'com.android.support.constraint:constraint-layout:1.0.2'
compile 'com.google.android.gms:play-services:6.5.87'
compile 'com.batch.android:batch-sdk:1.10+'
}
The support of batch.com was very great,
they help me to solve the bug by replacing google play services with this :
'com.google.android.gms:play-services-gcm:11.8.0'
I'm trying to set up a simple subscriber in my Android application using Greenrobot's Eventbus, but I am getting a gradle build error. I have shown my code below.
Event class
public final class OffersProcessedEvent {}
Base Fragment
public class BaseFragment extends Fragment {
private boolean registered;
#Override
public void onViewCreated(View view, #Nullable Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
EventBus.getDefault().register(this);
registered = true;
}
#Override
public void onResume() {
super.onResume();
if (!registered) {
EventBus.getDefault().register(this);
registered = true;
}
}
#Override
public void onPause() {
super.onPause();
EventBus.getDefault().unregister(this);
registered = false;
}
public AppCompatActivity getAppCompatActivity() {
return (AppCompatActivity) getActivity();
}
}
Event post'
EventBus.getDefault().post(new OffersProcessedEvent());
Subscribe code
#Subscribe
public void onMessageEvent(OffersProcessedEvent event){
*do whatever*
}
The following are my errors
Build Gradle Errors
Error:No option eventBusIndex passed to annotation processor
Error:Execution failed for task ':app:compileDebugJavaWithJavac'.
Compilation failed; see the compiler error output for details.
Gradle dependencies
dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
exclude group: 'com.android.support', module: 'support-annotations'
})
compile 'com.android.support:appcompat-v7:26.+'
compile 'com.android.support:design:26.+'
compile 'com.android.support.constraint:constraint-layout:1.0.2'
testCompile 'junit:junit:4.12'
compile 'com.facebook.android:facebook-android-sdk:4.5.0'
compile 'com.jakewharton:butterknife:8.6.0'
compile 'com.jakewharton:butterknife-compiler:8.6.0'
compile 'com.jakewharton:butterknife:8.7.0'
compile 'com.jakewharton:butterknife-compiler:8.7.0'
compile 'com.github.bumptech.glide:glide:3.5.2'
compile 'com.android.support:cardview-v7:26.0.0-alpha1'
compile 'com.google.code.gson:gson:2.8.1'
compile 'org.greenrobot:eventbus:3.0.0'
compile 'org.greenrobot:eventbus-annotation-processor:3.0.1'
}
apply plugin: 'kotlin-kapt' // ensure kapt plugin is applied
dependencies {
implementation 'org.greenrobot:eventbus:3.1.1'
kapt 'org.greenrobot:eventbus-annotation-processor:3.1.1'
}
kapt {
arguments {
arg('eventBusIndex', 'com.example.myapp.MyEventBusIndex')
}
}
Base on this link http://greenrobot.org/eventbus/documentation/faq/
This happens when you set up the build script, and you did not add any
annotations to your code yet. Without any #Subscribe annotations,
annotation processor for indexing will not be triggered to consume the
‘eventBusIndex’ option. So, just add some #Subscribe annotations and
you should be fine.
So you must add
#Subscribe
fun onEvent(event: SomeEvent) {
}
But is you steel getting Error:No option eventBusIndex passed to annotation processor
Add this to your app.gradle
If using annotationProcessor
defaultConfig {
//other code
javaCompileOptions {
annotationProcessorOptions {
arguments = [eventBusIndex: "com.example.myapp.MyEventBusIndex"]
}
}
}
If using kapt
dependencies {
//other codes
}
kapt {
arguments {
arg('eventBusIndex', 'com.example.myapp.MyEventBusIndex')
}
}
And if using android-apt
dependencies {
//other codes
}
apt {
arguments {
eventBusIndex "com.example.myapp.MyEventBusIndex"
}
}
And this file will be generate by EventBus
/** This class is generated by EventBus, do not edit. */
public class MyEventBusIndex implements SubscriberInfoIndex {
private static final Map<Class<?>, SubscriberInfo> SUBSCRIBER_INDEX;
static {
SUBSCRIBER_INDEX = new HashMap<Class<?>, SubscriberInfo>();
putIndex(new SimpleSubscriberInfo(MainActivity.class, true, new SubscriberMethodInfo[] {
new SubscriberMethodInfo("onBleClick", com.example.myapp.Events.BleClickListener.class),
}));
}
private static void putIndex(SubscriberInfo info) {
SUBSCRIBER_INDEX.put(info.getSubscriberClass(), info);
}
#Override
public SubscriberInfo getSubscriberInfo(Class<?> subscriberClass) {
SubscriberInfo info = SUBSCRIBER_INDEX.get(subscriberClass);
if (info != null) {
return info;
} else {
return null;
}
}
}
Hope it's help
After finding some people saying that FirebaseRecyclerAdapters are broken inside of fragments (and trying for about 4 hours to get it to work before that), I decided to switch to a FirebaseListAdapter, as I found examples of that working inside of fragments. However, I'm having issues. The populateView() method never seems to be firing and I'm getting no errors. Here is my code for the fragment:
public class PasteFromFirebasePopup extends DialogFragment implements AdapterView.OnClickListener {
Activity activity;
private FirebaseListAdapter mFirebaseAdapter;
private DatabaseReference mClipboardHistoryReference;
private ListView mListView;
public PasteFromFirebasePopup() {}
#Override public View onCreateView(LayoutInflater inflater, #Nullable ViewGroup container,
Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.clip_history_popup_list, container, false);
mListView = (ListView) rootView.findViewById(R.id.clipboardHistoryListView);
activity = getActivity();
mClipboardHistoryReference = FirebaseDatabase.getInstance().getReference(Constants.FIREBASE_CHILD_CLIPBOARD_HISTORY);
Log.d("clipboardRef", mClipboardHistoryReference.toString());
mFirebaseAdapter = new FirebaseListAdapter<FirebaseString>
(activity, FirebaseString.class, R.layout.clip_history_popup_item, mClipboardHistoryReference) {
TextView mTextView;
#Override protected void populateView(View v, FirebaseString model, int position) {
mTextView = (TextView) v.findViewById(R.id.clipboardHistoryTextView);
Log.d("model text", model.getText());
mTextView.setText(model.getText());
}
};
mListView.setAdapter(mFirebaseAdapter);
return rootView;
}
#Override public void onClick(View v) {}
#Override public void onDestroy() {
super.onDestroy();
mFirebaseAdapter.cleanup();
}
}
No matter what I try, the log inside of populateView() absolutely never fires. I have triple checked my reference, and there is indeed something in there (only one item at the moment, but as far as I can tell that shouldn't matter). Am I missing something? Does this not work inside of DialogFragments? If not, does anyone have a suggestion for a popup that can hold a FirebaseListAdapter/RecyclerAdapter successfully?
Any help is duly appreciated.
EDIT: my build.gradle (app) , as I think this may have something to do with it.
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
exclude group: 'com.android.support', module: 'support-annotations'
})
androidTestCompile('com.android.support.test:runner:0.3') {
exclude group: 'com.android.support', module: 'support-annotations'
}
compile 'com.squareup.okhttp3:okhttp:3.2.0'
compile 'com.github.smart-fun:XmlToJson:1.2.2'
compile 'com.android.support:appcompat-v7:25.3.1'
compile 'com.android.support.constraint:constraint-layout:1.0.2'
compile 'com.android.support:design:25.3.1'
compile 'com.android.support:gridlayout-v7:25.3.1'
compile 'com.android.support:recyclerview-v7:25.3.1'
compile 'com.android.support:support-v4:25.3.1'
testCompile 'org.robolectric:robolectric:3.0'
testCompile 'org.robolectric:shadows-support-v4:3.0'
testCompile 'junit:junit:4.12'
compile 'com.google.firebase:firebase-database:11.0.0'
compile 'com.firebaseui:firebase-ui-database:1.2.0'
compile 'com.google.android.gms:play-services:11.0.0'
compile 'org.parceler:parceler-api:1.1.6'
annotationProcessor 'org.parceler:parceler:1.1.6'
compile 'com.jakewharton:butterknife:8.6.0'
annotationProcessor 'com.jakewharton:butterknife-compiler:8.6.0'
}
apply plugin: 'com.google.gms.google-services'