Okay, so I've tried to import my unity project as a single activity in Android Studio.
I've followed this
tutorial
but I kept getting an error at step 6:
"Unable to resolve dependency for ‘:app#debug/compileClasspath’: Could not resolve project..."
So I turned to another tutorial on a different way to import the aar package to my main project file in android studio.
Now, using both of the tutorials together, I managed to put something together that will compile without an error.
This is my main activity, where I want to start the unity activity on a button click:
public class MainActivity extends AppCompatActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
public void startUnity(View view){
Intent intent = new Intent(this.getApplicationContext(), UnityPlayerActivity.class);
startActivity(intent);
}
}
The UnityPlayerActivity class is recognized by Android Studio, but when I run the app, I get this exception:
"Caused by: android.content.ActivityNotFoundException: Unable to find explicit activity class {com.zackguetta.foodiedoodie/com.unity3d.player.UnityPlayerActivity}; have you declared this activity in your AndroidManifest.xml?"
How do I fix this? I thought the merge of the manifests would take care of this.
*note: I'm using Android Studio 3.0.1 if it means anything to you (maybe some compatibility issues arise)
*second note: Yes, I went through the other similar topics, none seemed to have the answer, so please don't mark as a duplicate right away.
Add it to your AndroidManifest.xml. Write this line inside <application> tags:
<activity android:name=".unity3d.player.UnityPlayerActivity" />
Related
As an experiment, and as a way to force myself to understand the ins and outs of how tts works on Android, I thought it might be interesting to copy the source code for the TextToSpeech class into a new class in my project and rename it (and it's package name) to that of my project.
This of course results in many classes getting highlighted in red and needing to be re-attached and brought into my project as well.
So I began the process of repeating the same procedure -- copying the source of each missing class into a new class in my project -- which leads to more missing classes within that new class.
I was expecting these errors to happen, but in theory I was hoping it would be possible to graft the whole android.tts.* "tree" (or whatever parts were necessary in order to make the TextToSpeech class function) into my project.
Here's my code to illustrate:
MainActivity.java:
public class MainActivity extends AppCompatActivity {
// notice that this not android.speech.tts.TextToSpeech class, but a local copy of it.
MyTextToSpeech tts;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
tts = new MyTextToSpeech(getApplicationContext(), new MyTextToSpeech.OnInitListener() {
#Override
public void onInit(int i) {
if (i == TextToSpeech.SUCCESS) {
begin();
}
else {
Log.i("XXX", "init failed");
}
}
}, "com.google.android.tts");
}
private void begin() {
Log.i("XXX", "It seems to have initialized!");
}
}
I've gotten rid of most of the errors in my "custom" TextToSpeech class (plz just assume this error is the only one remaining), but there is this one class that I can't seem to pull into the project: ITextToSpeechService:
Apparently this is a hidden/internal "aidl" file the source of which is here.
I tried pasting it in a new folder named "aidl" (following this answer) and it "worked" in the sense that it existed in the aidl folder without errors, but when trying to compile it using gradle\tasks\other\compileDebugAidl, I got this error:
FAILURE: Build failed with an exception.
What went wrong:
Execution failed for task ':app:compileDebugAidl'.
1 exception was raised by workers:
java.lang.RuntimeException: java.lang.RuntimeException: java.io.IOException: com.android.ide.common.process.ProcessException: Error while executing process /Users/boober/Library/Android/sdk/build-tools/28.0.3/aidl with arguments {-p/Users/boober/Library/Android/sdk/platforms/android-29/framework.aidl -o/Users/boober/Desktop/SCRAP/TTSGraft/app/build/generated/aidl_source_output_dir/debug/out -I/Users/boober/Desktop/SCRAP/TTSGraft/app/src/main/aidl -I/Users/boober/Desktop/SCRAP/TTSGraft/app/src/debug/aidl -I/Users/boober/.gradle/caches/transforms-2/files-2.1/1cd7eff88f5e86d0249af2958bf465f0/core-1.1.0/aidl -I/Users/boober/.gradle/caches/transforms-2/files-2.1/929ec10604c047a76453df3294ada6ae/versionedparcelable-1.1.0/aidl -d/var/folders/vz/d68y33c14pjc9m2vrkqp2kvc0000gn/T/aidl4956045951058849495.d /Users/boober/Desktop/SCRAP/TTSGraft/app/src/main/aidl/com/booberbunz/ttsgraft/ITextToSpeechService.aidl}
... and it still would not resolve within MyTextToSpeech.java.
How to get this file into my project locally so that I no longer have the "can't resolve error" in red as seen in image?
And as an aside question: is this actually not possible to do -- to hardcode tts into a project?
Thanks.
I just added those AIDLs to a project and compile them. I've just added both ITextToSpeechService.aidl and ITextToSpeechCallback.aidl and removed imports, modified packages and added ITextToSpeechCallback import to ITextToSpeechService:
import com.android.speech.tts.ITextToSpeechCallback;
My files were under src/main/aidl/com/android/speech/tts
so the package in AIDLs is:
package com.android.speech.tts;
I have never used Android Studio before and have always been coding using NetBeans.
I need to create an app for Android, so I decided to use NetBeans. I created new project and it is 'empty' for now, however I have an error:
package Fridge.Freezer;
import android.app.Activity;
import android.os.Bundle;
public class MainActivity extends Activity
{
/** Called when the activity is first created. */
#Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
}
}
The error is in setContentView(R.layout.main); - cannot find package. Can anyone tell what I am doing wrong? Clean and build does not work.
erase your package name at the top and try to add it to getting the suggestion package import by shortcut Control + Enter beside "R"
Try checking following component in your project directory
R.java file
folder named layout
layout xml file named main.xmlmain
PS Since your are starting a fresh project, I would suggest you to start at Android Studio.
I tried cleaning the project and rebuilding it again. It did not work. The solution was to restart IDE.
I am creating simple android application in android of hello world printing and getting an -- error Description
Resource Path Location Type Error generating final archive: java.lang.ArrayIndexOutOfBoundsException: 13 Demo_ABC Unknown Android Packaging Problem
Code is:
import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
public class MainActivity extends Activity
{
#Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
}
Someone else had the same problem with eclipse. The solution was to check the box "Create Test Project":
Your project is getting associated with some Test Project which you are not mapping with your newly created project. When you are creating any new project check carefully whether you are including the "Create Test Project" option or not.
Another guess: As the error seems to be package-related and your code does not include that, insert the correct package yourpackage.tld; in the code. (you said "Code is:").
Maybe that is missing Android expects it by default and gives weird errors because that was totally unforseen by the Google Android developers.
I'm currently having a curious problem, trying to use simultaneously v4 and v7 (actionbar) compatibility libs.
Let's say I've got my own Activity class, that extends ActionBarActivity on one hand and, on the other hand a Fragment, inside of which I call "(MyActivity)getActivity()".
I checked the imports and my Fragment is a v4 Fragment.
In a v4 Fragment, calling "getActivity()" returns a FragmentActivity.
I also checked: ActionBarActivity extends FragmentActivity.
Now here is my problem:
I don't have any error in the editor (no red line).
I'm using Android Studio.
When I try to "Make" the project, the compiler returns an error for each time I call "getActivity" inside my Fragment.
It tells me he has a FragmentActivity but a ActionBarActivity is expected and tells me those classes are incompatible.
It interrupts and I can't even test my app.
It may be a problem with the gradle configuration, but I added "compile "compile "com.android.support:appcompat-v7:18.0.+"" in the "dependencies" part of my build.gradle file, as said on this page:"http://developer.android.com/tools/support-library/setup.html", and it doesn't change anything...
Any idea?
EDIT :
As an adddition to my yesterday's post, even if everything is explain before, here are some code parts and the error message Android-Studio gives me:
First of all, my activity:
...
import android.support.v7.app.ActionBarActivity;
...
public abstract class MyAbstractActivity extends ActionBarActivity{
//Do some stuff here
}
Every activity of my application extends this class.
Now here is my fragment:
...
import android.support.v4.app.Fragment;
import android.support.v7.app.ActionBar;
...
public class MyFragment extends Fragment {
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
//Do some stuff...
((MyAbstractActivity)getActivity()).getSupportActionBar().setTitle(R.string.app_name);
}
//Do some stuff...
}
No error is shown in the editor.
But when I "Make" the project, I get this message in the "Event Log":
Compilation completed with 5 errors and 0 warnings in 4 sec
In the "Messages Make" part, I can see this for each time I try to cast "getActvity()" in "MyAbstractActivity":
java: inconvertible types
required: com.myapps.abstracts.MyAbstractActivity
found: android.support.v4.app.FragmentActivity
Well, I'm sad to say that, but I finally downloaded Eclipse, imported my project, and solved my problem, using the error messages of Eclipse.
It told me to "Fix Project Properties", I clicked, it did everything on his side, I tryed to launch the app, it worked.
Now that the problem is fixed, when I come back to Android Studio, it works too... But, for the moment, I think I'm gonna stay with Eclipse... Too much time lost for nothing. :(
Android Eclipse plugin gets flaky. Try to clean your project, then rebuild. Also, try restarting Eclipse. Also verify your project build path library order. Also, try to rebuild from the command line in the project with 'ant clean; ant debug', but do it while Eclipse is closed.
When I try to run the Hello, Android Activity, it says: emulator: ERROR: no search paths found in this AVD's configuration.
And underneath that it says: Weird, the AVD's config.ini file is malformed. Try re-creating it.
I'm stumped and would really appreciate if someone could help me out.
This is what I have for the code:
package my.helloandroid.activity;
import android.app.Activity;
import android.os.Bundle;
import android.widget.TextView;
public class HelloAndroidActivity extends Activity {
/** Called when the activity is first created. */
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
TextView tv = new TextView(this);
tv.setText("Hello, Android");
setContentView(tv);
}
}
Check the manifest file or look here:
Trouble getting Android emulator to run in eclipse
Three things which came to my mind.
Be sure to check if you have correct path to avd, Window->preferences.
Press right mouse button on your project folder and use android tools -> fix project.
simply restart eclipse.