Problems with Android Studios 1.5.1 - java

This Question seems like it's been answered but not updated, I am working on Android Studios 1.5.1.0 and I am getting an error in the activity_main.xml and also in the MainActivity.java. When making my app I had no problems until i tried to run it.
This is what came up when I tried to run it
Error:(13, 24) No resource found that matches the given name (at 'theme' with value '#style/AppTheme.AppBarOverlay').
Error:(20, 29) No resource found that matches the given name (at 'popupTheme' with value '#style/AppTheme.PopupOverlay').
Error:Execution failed for task ':app:processDebugResources.
com.android.ide.common.process.ProcessException: org.gradle.process.internal.ExecException: Process 'command 'C:\Android\sdk\build-tools\23.0.2\aapt.exe'' finished with non-zero exit value 1
In my activity_main.xml
<android.support.design.widget.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="#style/AppTheme.AppBarOverlay">
<android.support.v7.widget.Toolbar
android:id="#+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary"
app:popupTheme="#style/AppTheme.PopupOverlay" /> This is in red
</android.support.design.widget.AppBarLayout>
<include layout="#layout/content_main" />
<android.support.design.widget.FloatingActionButton
android:id="#+id/fab"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom|end"
android:layout_margin="#dimen/fab_margin"
android:src="#android:drawable/ic_dialog_email" />
and in my mainactivity.java
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
final EditText tickets = (EditText)findViewById(R.id.txtTickets);
final Spinner group = (Spinner)findViewById(R.id.txtGroup);
Button cost = (Button)findViewById(R.id.btncost);
cost.setOnClickListener(new View.OnClickListener() {
final TextView result = ((TextView)findViewById(R.id.txtResult);
#Override
public void onClick(View v) {
numberOfTickets = Integer.parseInt(tickets.getText().toString());
totalCost = costPerTickets * numberOfTickets;
DecimalFormat currency = new DecimalFormat("$###,###.##");
groupchoice = group.getSelectedItem().toString();
result.setText("Cost for " + groupchoice + " is " + currency.format(totalCost));
}
});
}
All (R.) is in Red

Whenever my R is red, I've found that it's because one of my resource XML files was badly formed, such that it wouldn't compile to create the R class. Inspect recent changes to your resource files and look for problems (tag errors, wrong quotes, etc).

You must define "AppTheme.AppBarOverlay" and "AppTheme.PopupOverlay" in values/style first

clean and rebuild your project
change the version of buildTools to :
buildToolsVersion "23.0.2"
Get this setting inside the file app/build.gradle.

Did you check some of the other answers on how to update your build.gradle file?
here and here, for me worked after restart of Android Studio 2.2.2 and update.

Related

Unknown bits set in runtime_flags: 0x28000

I made a simple app using Cards in Material Components in Android. When I try to run it in my "OnePlus AC2001" mobile, I'm getting this error in logcat.
2021-01-31 17:28:59.544 26933-26933/? E/rialdesigncard: Unknown bits set in runtime_flags: 0x28000
But I'm not getting any error when I run the app in the emulator.
This is my MainActivity.java file:
public class MainActivity extends AppCompatActivity {
CardView cardView;
TextView textView;
CheckBox checkBox;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
init();
}
private void init() {
cardView = findViewById(R.id.my_card_ui);
textView = findViewById(R.id.title_text);
checkBox = findViewById(R.id.checkbox);
cardView.setOnClickListener(v -> {
checkBox.setChecked(checkBox.isChecked()? false: true);
textView.setText("First title");
});
}
}
This is my ActivityMain.xml:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<com.google.android.material.card.MaterialCardView
android:id="#+id/my_card_ui"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:checkable="true"
android:clickable="true"
android:focusable="true">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:padding="30dp">
<CheckBox
android:id="#+id/checkbox"
android:layout_width="30dp"
android:layout_height="30dp" />
<TextView
android:id="#+id/title_text"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Title 1"
android:textColor="#color/black"
android:textSize="30dp"
android:textStyle="bold" />
<TextView
android:id="#+id/title_para"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="I am a paragraph and I am in a card. I am a paragraph and I am in a card. I am a paragraph and I am in a card."
android:textColor="#color/purple_700"
android:textSize="20dp" />
</LinearLayout>
</com.google.android.material.card.MaterialCardView>
</LinearLayout>
I couldn't find the solution to this error anywhere. Please help me solve this.
I have been consistently seeing this error for some time now (OnePlus device), but I haven't been able to find a solution either. The error does not seem to impact the app in any way though.
Additional point of information:
I have observed that this error appears in the Logcat whenever I Run/Debug the app on a real device, but it does not show up consistently in the Run/Debug consoles. I haven't tried to check (as you have) if the error is replicated when using an emulator.
Also, my Logcat shows the Unknown bits set in runtime_flags: 0x20000 error for many other packages as the device is running. Some examples: .android.dialer, oneplus.weather, twitter.android, and so on.
This is what I've found out so far:
From the ARM DS5 DUI0446U Debugger User Guide, a possible memory map for internal RAM can be between 0x8000 and 0x28000. I'm not from a computer engineering background, and I'm not sure if this is a relevant direction for understanding the problem further. Searching the Android Runtime (ART) site (this, or in general, this) yielded no useful results.
For a related error, by following this answer to the ART source code, 0x28000 seems to be related to either the DEBUG_IGNORE_APP_SIGNAL_HANDLER flag or the DISABLE_TEST_API_ENFORCEMENT_POLICY flag (line 154-155 as of this time of this post). [E.g., 1 << 17 is 0x20000]
I don't have a deeper understanding of the either of the two flags. Nevertheless, the 0x20000 error seems to be pretty commonplace in production apps. While this is not an indication that the 0x28000 error is equally hassle-free, to my mind it does shed some light on the nature of the runtime_flags.
It just might be the case that errors related to these flags (see the enum in the source code) may not really "break" the app. Some further information is required in order to be absolutely certain, but the above might be good enough to not be concerned about the app breaking.
P.S.: If you think this response is good enough, do mark it as an answer so I will have some feedback as well.

Android Studio: Resources.NotFoundException

My code ran fine on the emulator, however, as soon as I tried running my code on a device (in this case a Nexus 5) I started to get A LOT of Resources.NotFoundExceptions. The majority of the exceptions occur in relation to drawable or color files. For example:
android.content.res.Resources$NotFoundException: File res/drawable/blob_ocean.xml from drawable resource ID #0x7f060066
Logcat then states that the error is caused by:
Caused by: android.content.res.Resources$NotFoundException: File res/drawable/blob_ocean.xml from drawable resource ID #0x7f060066
then it states that the previous error is caused by:
Caused by: android.content.res.Resources$NotFoundException: File res/color/radial_pink.xml from color state list resource ID #0x7f04004e
The two examples occur in a fragment on the line with the AnimatedVectorDrawable.
public class BlobFragment extends Fragment {
private AnimatedVectorDrawable blob;
private ImageView blobView;
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View v = inflater.inflate(R.layout.blob_fragment, container, false);
blobView = (ImageView) v.findViewById(R.id.blob_o);
blob = (AnimatedVectorDrawable) ResourcesCompat.getDrawable(getResources(), R.drawable.blob_ocean, null);
blobView.setImageDrawable(blob);
blob.start();
return v;
}
}
The layout for the fragment looks like this:
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".OceanThemeActivity">
<ImageView
android:id="#+id/blob_o"
android:layout_width="300dp"
android:layout_height="300dp"
android:orientation="vertical"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.497"
app:srcCompat="#drawable/blob_ocean"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.271"/>
</androidx.constraintlayout.widget.ConstraintLayout>
I have looked online but have not been able to find something that works. Having a hard time identifying the issue as everything is working fine in an emulator.
I solved the issue. It was related to backward compatibility; I was using AnimatedVectorDrawable which is only working for API 24 or higher and my device was lower. Changing the objects to AnimatedVectorDrawableCompat fixed it. Also, some of the drawable recourses were too big, making them smaller worked perfectly fine.

Invalid drawable tag vector - appcompat-v7:24.1.1

OK I've read most of available answer on similar questions but nothing fixed my problem
gradle classpath 'com.android.tools.build:gradle:2.1.2'
android {
defaultConfig {
minSdkVersion 16
targetSdkVersion 24
vectorDrawables.useSupportLibrary = true
}
}
dependencies {
compile 'com.android.support:recyclerview-v7:24.1.1'
compile 'com.android.support:appcompat-v7:24.1.1'
compile 'com.android.support:cardview-v7:24.1.1'
compile 'com.android.support:support-v4:24.1.1'
compile 'com.android.support:design:24.1.1'
}
activity.xml
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/ScrollView"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".ViewItem"
tools:ignore="MissingPrefix">
...
<ImageView
android:id="#+id/imageView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_column="0"
android:layout_gravity="center_vertical"
android:layout_marginBottom="10dp"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
android:layout_marginTop="10dp"
android:foregroundGravity="center_vertical|center|center_horizontal"
app:srcCompat="#drawable/ic_car" />
...
</ScrollView>
vector ic_car.xml
<?xml version="1.0" encoding="utf-8"?>
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportHeight="24"
android:viewportWidth="24">
<path
android:fillColor="#5c5c5c"
android:pathData="M18.92 6.01C18.72 5.42 18.16 5 17.5 5h-11c-.66 0-1.21 .42 -1.42 1.01L3 12v8c0
.55 .45 1 1 1h1c.55 0 1-.45 1-1v-1h12v1c0 .55 .45 1 1 1h1c.55 0 1-.45
1-1v-8l-2.08-5.99zM6.5 16c-.83 0-1.5-.67-1.5-1.5S5.67 13 6.5 13s1.5 .67 1.5
1.5S7.33 16 6.5 16zm11 0c-.83 0-1.5-.67-1.5-1.5s.67-1.5 1.5-1.5 1.5 .67 1.5
1.5-.67 1.5-1.5 1.5zM5 11l1.5-4.5h11L19 11H5z" />
<path android:pathData="M0 0h24v24H0z" />
</vector>
my activity class extends AppCompatActivity and all android:src tags are changed to app:srcCompat but still I see Invalid drawable tag vector error on the minSdkVersion which is set to 16.
In my case, the crash happened due to using Resources.getDrawable(int) to get the vector drawable on pre-lollipop devices. I was trying to create a drawable to pass into
ImageView.setImageDrawable(Drawable).
Google Blog Post for Android Support Library 23.2:
As of Android Support Library 23.3.0, support vector drawables can
only be loaded via app:srcCompat or setImageResource().
Solution: Use VectorDrawableCompat.create(Resources, int, Theme) to create the drawable.
You can also use ImageView.setImageResource(int) however this will read/decode the bitmap on the UI thread.
Truth is, looking at your code, it should work in any version of the library, as you are using only the srcCompat attribute.
One issue I suspect, is that your vector is in a drawable-21 folder, while in the regular Drawable folder you have single file that references these Drawables. This was a method done in early versions of the library, but does not work anymore due to changes below. Just move the actual vector file to the Drawable folder.
We have had sometimes similar issues that were solved by changing the ImageView to an AppCompatImageView. Even though the library is supposed to do this automatically, it seems that sometimes it doesn't.
It is still possible that the code is breaking if your vector is part of a compound image, for example a layered image. Or it's breaking somewhere else for which you have not posted the code, for example if you are setting a vector as the leftImage on an ImageButton. These functionalities have been removed in 23.3, as #Zeke has answered. Nonetheless, it was returned in 23.4, made usable by adding the following to your activity
static {
AppCompatDelegate.setCompatVectorFromResourcesEnabled(true);
}
They still warn you it can cause memory leaks. See https://medium.com/#chrisbanes/appcompat-v23-2-age-of-the-vectors-91cbafa87c88#.s48hqaw1u, though for minimal use it shouldn't be an issue.
A simple workaround would be to create the Drawable and set it in code. Something like this;
Drawable icon = AppCompatDrawableManager.get().getDrawable(context, resVectorID);
// Set it for example as a left image of button
button.setCompoundDrawablesWithIntrinsicBounds( icon, null, null, null );
I have not tested this, and have no ideas if this causes memory issues or not. Would love it if someone can follow up.
Problem got solved itself after updating to Android studio 2.2
I did like this:
public static final Drawable getMyDrawable(Context context, int id) {
final int version = Build.VERSION.SDK_INT;
if (version >= 21) {
return ContextCompat.getDrawable(context, id);
} else {
return VectorDrawableCompat.create(context.getResources(), id, context.getTheme());
}
}

Amazon ads api crashing my app?

The following classes could not be instantiated:
- com.amazon.device.ads.AdLayout (Open Class, Show Error Log)
See the Error Log (Window > Show View) for more details.
Tip: Use View.isInEditMode() in your custom views to skip code when shown in Eclipse
java.lang.NoClassDefFoundError: Could not initialize class android.os.Environment
at com.amazon.device.ads.DebugProperties.readDebugProperties(DebugProperties.java:75)
at com.amazon.device.ads.InternalAdRegistration.<init>(InternalAdRegistration.java:52)
at com.amazon.device.ads.InternalAdRegistration.getInstance(InternalAdRegistration.java:64)
at com.amazon.device.ads.AdLayout.initialize(AdLayout.java:185)
at com.amazon.device.ads.AdLayout.initialize(AdLayout.java:176)
at com.amazon.device.ads.AdLayout.<init>(AdLayout.java:120)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0( at sun.reflect.NativeConstructorAccessorImpl.newInstance( at sun.reflect.DelegatingConstructorAccessorImpl.newInstance( at java.lang.reflect.Constructor.newInstance( at com.android.ide.eclipse.adt.internal.editors.layout.ProjectCallback.instantiateClass(ProjectCallback.java:422)
at com.android.ide.eclipse.adt.internal.editors.layout.ProjectCallback.loadView(ProjectCallback.java:179)
at android.view.BridgeInflater.loadCustomView(BridgeInflater.java:207)
at android.view.BridgeInflater.createViewFromTag(BridgeInflater.java:135)
at android.view.LayoutInflater.rInflate_Original(LayoutInflater.java:755)
at android.view.LayoutInflater_Delegate.rInflate(LayoutInflater_Delegate.java:64)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:727)
at android.view.LayoutInflater.inflate(LayoutInflater.java:492)
at android.view.LayoutInflater.inflate(LayoutInflater.java:373)
My main.xml looks like this
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:Amazon="http://schemas.android.com/apk/lib/com.amazon.device.ads"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/LinearLayout1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:gravity="top|center_horizontal" >
<com.amazon.device.ads.AdLayout
android:id="#+id/myAdView"
android:layout_width="fill_parent"
android:layout_height="wrap_content" />
<ScrollView
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
My MainActivity.java is this
import com.amazon.device.ads.AdLayout;
import com.amazon.device.ads.AdRegistration;
import com.amazon.device.ads.AdTargetingOptions;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
preferences = PreferenceManager.getDefaultSharedPreferences(this);
int defaultValue = R.drawable.blue;
int themedefault = ThemeChanger.THEME_BLUE;
appliedtheme = preferences.getInt("mytheme", themedefault);
ThemeChanger.onActivityCreateSetTheme(this, appliedtheme);
setContentView(R.layout.main);
AdRegistration.setAppKey("Application_Key");
this.adView = (AdLayout) findViewById(R.id.myAdView);
this.adView.loadAd(new AdTargetingOptions());
button1 = preferences.getInt("DigitButtonStyle", defaultValue);
buttonmadd = preferences.getInt("MemoryButtonStyle", defaultValue);
buttoncos = preferences.getInt("FunctionButtonStyle", defaultValue);
I had the same issue and followed Amazon developer guide. To solve this issue, just copy amazon library and paste it in your libs folder and than run.
It's a known issue in Eclipse ADT plugin, even if you use View.isInEditMode(), in some cases, it crashes in recent API versions (higher than 18). It's fixed in Android Studio.
If you want to see Layout Preview, you can try with different API version lower than 19.
Check the screenshot. It's using API 18. (Red box is Amazon AdLayout)

Real Admob Ads Appearing When Setting Test Mode Programmatically

Kind of a strange issue here: Whenever I set test mode via xml, I receive the expected test ads in my emulator. However, when I try to do the same programmatically, I seem to get real ads. According to the Admob documentation, these two methods should be equivalent, no? Here is my xml code:
<com.google.ads.AdView
android:id="#+id/adView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
ads:adSize="BANNER"
ads:adUnitId="xxxxxxxxxxx"
ads:loadAdOnCreate="true">
</com.google.ads.AdView>
And here is the relevant Java code:
#Override
public void onCreate(Bundle savedInstanceState) {
requestWindowFeature(Window.FEATURE_NO_TITLE);
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
AdRequest adRequest = new AdRequest();
adRequest.addTestDevice(AdRequest.TEST_EMULATOR);
}
As mentioned before, if I insert the line ads:testDevices="TEST_EMULATOR, TEST_DEVICE_ID" into the above xml code, I get the test ad just fine. Any ideas?
I believe you have to call .loadAd(adRequest) on the AdView object.
See Google's AdMob documentation here
In the Adding a com.google.ads.AdView section.
You don't have to call it programmatically.
It took me a while until I get what device is AdMob's sdk what expecting cuz' I was thinking it was something related to the real device like ( adb devices )
But here is a comment from the official documentation that cleared it up.
"There will be a log message with the code needed to add the current device to the list of test devices"
You may get a message akin to it
I/Ads(26674): To get test ads on this device, call adRequest.addTestDevice("F1254CDFBA84BDC27F5C7C6E12445D06");
All you have to do after that is to place this ID into your layout xml as below
<com.google.ads.AdView
android:layout_alignParentBottom="true"
android:id="#+id/adView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
ads:adSize="BANNER"
ads:adUnitId="#string/publisherId"
ads:loadAdOnCreate="true"
ads:testDevices="TEST_EMULATOR, F1254CDFBA84BDC27F5C7C6E12445D06" />
Hope it helps you guys out
Paulo Miguel Almeida

Categories