Search code examples
androidandroid-ndkcocos2d-x

Getting "package R does not exist" when building from command-line


I created an activity on a separate project using Eclipse. When I imported it into my cocos2d-x android project and built the project using python build_native.py (which is basically building the app using the NDK) and ant debug, I get an error saying:

error: package R does not exist

pointing to the line:

setContentView(R.layout.some_activity);
                ^

I have added the res/layout/some_activity.xml in my cocos2d-x project as well as the manifest entries:

<application
    <!-- <application> tag info --> >
    <activity
        <!-- cocos2d-x native activity --> >
    </activity>

    <!-- the activity I imported -->
    <activity
        android:name="com.mycompany.myapp.SomeActivity"
        android:label="" 
        android:theme="@android:style/Theme.Dialog"
        android:excludeFromRecents="true" 
        android:noHistory="true" 
    />
</application>

I also copied the needed *.java files inside the src folder (in the exact same folder structure). I also tried cleaning manually (by deleting the bin, gen, obj, and assets folders) and through ant clean. I am not using Eclipse to build, only from the command-line.

EDIT: I also tried adding import com.mycompany.myapp.R; as well as import com.mycompany.R; on SomeActivity.java but it still didn't fix it.

How do I fix this error? Any other steps I am missing?


Solution

  • I had to import the cocos2d-x project's package name, not the imported activity's package name.

    For example, if your cocos2d-x project's package name was com.mycompany.cocosapp and your imported activity's package name was com.mycompany.myapp, import com.mycompany.cocosapp.R instead of com.mycompany.myapp.R.